我有一個專案,我正在嘗試使用 TeamCity 在 .NET 6 下構建。構建總是失敗并顯示錯誤訊息:
錯誤 MSB4062:無法從程式集中加載“TransformXml”任務...
我找到了這個執行緒并決定安裝MSBuild.Microsoft.VisualStudio.Web.targets Nuget 包。現在我的 .csproj 檔案如下所示:
<Import Project="$(NuGetPackageRoot)MSBuild.Microsoft.VisualStudio.Web.targets\14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.Publishing.targets" Condition="true" />
<UsingTask TaskName="TransformXml" AssemblyFile="$(NuGetPackageRoot)MSBuild.Microsoft.VisualStudio.Web.targets\14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="ApplyConfigurationConfigFile" AfterTargets="PrepareForBuild" Condition="Exists('App.$(EnvironmentName).config')">
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
<TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(EnvironmentName).config" />
</Target>
我已經嘗試了十幾種不同的方法來做到這一點,但它總是回傳相同的錯誤訊息:
錯誤 MSB4062:無法從程式集 C:\Program Files\dotnet\sdk\6.0.108\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.Tasks.dll 加載“TransformXml”任務。無法加載檔案或程式集“C:\Program Files\dotnet\sdk\6.0.108\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.Tasks.dll”。該系統找不到指定的路徑。確認宣告正確,程式集及其所有依賴項都可用,并且任務包含實作 Microsoft.Build.Framework.ITask 的公共類。
我真的不明白這一點,因為肯定$(NuGetPackageRoot)應該指向其他檔案夾?
實際上,我什至嘗試過使用 SlowCheetah Nuget 包,但它以相同的錯誤訊息失敗(顯然它在內部呼叫了原始的 TransformXml 任務)。
有人知道怎么修這個東西嗎?
uj5u.com熱心網友回復:
使這項作業的訣竅是<Project SDK="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">。
添加 Microsoft.NET.Sdk.Publish 使<TransformXml>任務可用。無需使用 Nuget 包或任何東西。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/508657.html
