我试图在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有关,但我不知道如何正确解决此问题
答案 0 :(得分: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>
这最终对我有用。
答案 1 :(得分:0)
小错误。应该在即将到来的新3.1.103中修复,而不是现在的3.1.102。
问题是路径Program Files (x86)' where
(x86)is escaped to
%28x86%29`,导致找不到路径。
通过转义路径临时修复:
转到:
C:\ Program Files(x86)\ dotnet \ sdk \ 3.1.102 \ Sdks \ Microsoft.NET.Sdk.WindowsDesktop \ targets
编辑Microsoft.WinFx.props并使用此_PresentationBuildTaskAssembly,该路径的路径为Unescape:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$([MSBuild]::Unescape($([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll'))))</_PresentationBuildTasksAssembly>
还可以通过在Visual Studio中将内部版本更改为x64而不是Any CPU / x86来解决该问题。对于64位,它将使用C:\Program Files\
而不是C:\Program Files (x86)\
,因此没有“坏”字符。