在VScode中构建WPF应用程序给了我错误MSB4062

问题描述 投票:1回答:1

我正在尝试在Visual Studio Code中的WPF(.Net Core 3.1)上执行构建(这次不是Visual Studio,因为我需要一个更轻便的编辑器。通常我的所有项目都可以很好地构建,但是这个WPF项目给了我以下错误:

C:\Program Files (x86)\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.
WinFX.targets(225,9): error MSB4062: The "Microsoft.Build.Tasks.Windows.MarkupCompilePass1" task could not be loaded from
 the assembly C:\Program Files %28x86%29\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\netcoreapp2.1\PresentationBuildTasks.dll. Could not load file or assembly 'C:\Program Files 
%28x86%29\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\netcoreapp2.1\PresentationBuildTasks.dll'. The system cannot find the path specified.
Confirm that the <UsingTask> declaration is correct, that the assembly and all 
its dependencies are available, and that the task contains a public class that 
implements Microsoft.Build.Framework.ITask. [E:\ui_wpf_test\ui_wpf_test.csproj]

The build failed. Fix the build errors and run again.

我听说这与MSbuild有关,但我不知道如何正确解决此问题

c# wpf msbuild
1个回答
0
投票

我在GitHub上找到了解决方案。您必须替换%ProgramFiles(x86)%\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFx.props的以下行:

<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll'))</_PresentationBuildTasksAssembly>

替换为:

<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll</_PresentationBuildTasksAssembly>

这最终对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.