且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么修改项目输出目录会导致:IOException未处理“无法找到资源'app.xaml'".

更新时间:2023-11-22 12:49:22

将MSBuild输出的详细程度设置为诊断"很快就会发现问题的根源:

Setting the MSBuild output verbosity to "Diagnostic" quickly revealed the source of the problem:

1>   (TaskId:21)
1>  Microsoft (R) Build Task 'ResourcesGenerator' Version '4.0.30319.33440 built by: FX45W81RTMREL'. (TaskId:21)
1>  Copyright (C) Microsoft Corporation 2005. All rights reserved. (TaskId:21)
1>  
1>   (TaskId:21)
1>  Generating .resources file: '..\Build/Obj_Exe/WpfApplication8_AnyCPU_Debug/WpfApplication8.g.resources'... (TaskId:21)
1>  Reading Resource file: 'C:\Users\hpass_000\Projects\Build\Obj_Exe\WpfApplication8_AnyCPU_Debug\MainWindow.baml'... (TaskId:21)
1>  Resource ID is 'mainwindow.baml'. (TaskId:21)
1>  Generated .resources file: '..\Build/Obj_Exe/WpfApplication8_AnyCPU_Debug/WpfApplication8.g.resources'. 

请注意路径名中正斜杠和反斜杠的混合使用. Windows本身知道如何很好地处理路径名中的正斜杠.但是在其他软件中通常缺少该功能,而在资源生成器任务中却缺少该功能.这需要使用真正的反斜杠作为路径分隔符,正斜杠在资源名称中有效.修复:

Note the mix of forward and backward slashes in the path names. Windows itself knows how to handle forward slashes in path names well. But that capability is often lacking in other software, it is lacking in the resource generator task. Which requires a true backslash as a path separator, a forward slash is valid in a resource name. Fix:

 <OutputPath>$(OutputRelativePath)\$(AssemblyName)_$(Platform)_$(Configuration)\</OutputPath>
 <BaseIntermediateOutputPath>$(OutputRelativePath)\Obj_Exe\$(AssemblyName)_$(Platform)</BaseIntermediateOutputPath>
 <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)\</IntermediateOutputPath>

换句话说,我只是将/替换为\.解决了问题.

In other words, I simply replaced / with \. Which solved the problem.