The “TransformAppSettings” task failed unexpectedly

陌路散爱 提交于 2019-12-06 05:13:40

问题


I have a .NET Core 3 Blazor (server side) application which I recently upgraded to .NET Core 3.0.1 preview 6 version from the preview 5 version. When I build and run it locally, it works fine; but when trying to publish it to a file system folder (in Framework-Dependent mode), it throws this error:

C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(192,5): Error MSB4018: The "TransformAppSettings" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. File name: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

at Microsoft.NET.Sdk.Publish.Tasks.AppSettingsTransform.UpdateDestinationConnectionStringEntries(String destinationAppSettingsFilePath, ITaskItem[] destinationConnectionStrings) at Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal() at Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

It's perhaps worth mentioning that this error didn't occur in the preview 5 version. Also, I use Visual Studio Enterprise 2019 (Windows).

Things I've tried so far: (with no luck)

  • Clean/Rebuild solution
  • Reinstall .NET Core 3 preview 6 SDK
  • Add Newtonsoft.Json package via Nuget
  • Search for related issues raised by the community on github

.csproj file

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>7.3</LangVersion>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.1.0" />
    <PackageReference Include="MatBlazor" Version="1.2.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="SqlTableDependency" Version="8.5.3" />
    <PackageReference Include="System.DirectoryServices" Version="4.5.0" />
    <PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.5.0" />
    <PackageReference Include="Telerik.UI.for.Blazor" Version="1.1.1" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\images\" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\{path to project file}" />
  </ItemGroup>

</Project>

回答1:


In my case, I edit the publish configuration and turned off the Database -> Use this connection at runtime. Then I could publish without this error, however, I had to manually edit the web.config and make the following changes.

modules="AspNetCorModuleV2"  had to become modules="AspNetCodeModule"

hostingModel="InProcess" had to become hostingModel="OutOfProcess" 

<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> had to become value="Production"

These changes were already in my own directories web.config, but they didn't seem to get propagated in the publish anymore.




回答2:


I have the same issue

Same Question on Stack Overflow

Though i have managed to publish my project via powershell commands

dotnet publish --configuration Release --framework netcoreapp2.2

Try it, I hope it will help...



来源:https://stackoverflow.com/questions/56996326/the-transformappsettings-task-failed-unexpectedly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!