在VS2012中读取任何WPF项目的资源文件时出错

每当我尝试在VS2012中编译任何WPF项目时,我都有以下编译错误:

读取资源文件’c:\ Users \ mysuerID \ Documents \ Visual Studio 2012 \ Projects \ MyAppNAme \ MyAppNAme \ obj \ Debug \’时出错 – ‘系统找不到指定的路径。 ‘C:\ Users \ mysuerID \ Documents \ Visual Studio 2012 \ Projects \ MyAppNAme \ MyAppNAme \ CSC MyAppNAme

问题是当VS生成CSC命令时,它包含一个额外的部分重复/资源参数,如下所示:

/resource:obj\Debug\ /resource:obj\Debug\MyAppName.Properties.Resources.resources 

CSC仅查看第一个参数,因为没有指定文件名,所以它会抛出错误。 我进入命令行模式并使用和不使用额外参数进行测试并validation它是问题所在。 我不想手动编译我的项目!

任何人都知道VS如何提出这些参数以及如何摆脱这个额外的无效参数?

构建输出看起来像这样(框架4.5)

 1>Target "MainResourcesGeneration" in file "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets" from project "C:\Users\jws15592\Documents\Visual Studio 2012\Projects\MyAppName\MyAppName\MyAppName.csproj" (target "PrepareResources" depends on it): 1>Building target "MainResourcesGeneration" completely. 1>Input file "C:\Users\jws15592\Documents\Visual Studio 2012\Projects\MyAppName\MyAppName\obj\Debug\MainWindow.baml" is newer than output file "obj\Debug\". 1>Task "Message" skipped, due to false condition; ('$(MSBuildTargetsVerbose)'=='true') was evaluated as (''=='true'). 1>Using "ResourcesGenerator" task from assembly "PresentationBuildTasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". 1>Task "ResourcesGenerator" 1> 1> 1> Microsoft (R) Build Task 'ResourcesGenerator' Version '4.0.30319.17929 built by: FX45RTMREL'. 1> Copyright (C) Microsoft Corporation 2005. All rights reserved. 1> 1> 1> Generating .resources file: 'obj\Debug\'... 1>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets(709,5): error RG1000: Unknown build error, 'Could not find a part of the path 'C:\Users\jws15592\Documents\Visual Studio 2012\Projects\MyAppName\MyAppName\obj\Debug\'.' 1>Done executing task "ResourcesGenerator" -- FAILED. 1>Done building target "MainResourcesGeneration" in project "MyAppName.csproj" -- FAILED. 

项目文件中的ItemGroup:

    Code   True True Resources.resx   True Settings.settings True   ResXFileCodeGenerator Resources.Designer.cs    SettingsSingleFileGenerator Settings.Designer.cs    

这不是一个额外的论点,它是一个不完整的论点。 您通常希望在那里看到/resource:obj\Debug \ MyAppName.g.resources。 有些东西使文件名计算为空字符串。 它是从您应用中的.xaml文件生成的。

工具+选项,项目和解决方案,构建和运行,“MSBuild项目构建输出详细程度”设置,将其更改为详细。 您现在将获得构建步骤的非常详细的跟踪。 将其复制/粘贴到记事本中,然后启用Format + Word Wrap,这样您就可以看到所有内容。

生成MyAppName.g.resources文件的预期构建步骤如下所示:

 1>Output file "obj\Debug\MyAppName.g.resources" does not exist. 1>Task "Message" skipped, due to false condition; ('$(MSBuildTargetsVerbose)'=='true') was evaluated as (''=='true'). 1>Using "ResourcesGenerator" task from assembly "PresentationBuildTasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". 1>Task "ResourcesGenerator" 1> 1> 1> Microsoft (R) Build Task 'ResourcesGenerator' Version '4.0.30319.17929 built by: FX45RTMREL'. 1> Copyright (C) Microsoft Corporation 2005. All rights reserved. 1> 1> 1> Generating .resources file: 'obj\Debug\MyAppName.g.resources'... 1> Reading Resource file: 'C:\Users\hpass_000\AppData\Local\Temporary Projects\MyAppName\obj\Debug\MainWindow.baml'... 1> Resource ID is 'mainwindow.baml'. 1> Generated .resources file: 'obj\Debug\MyAppName.g.resources'. 

与你的比较,并告诉我们你看到的不同。


更新:显然这个构建步骤出于同样的原因出错了。 输入文件正确生成。 我可以将其缩小到具有空字符串的MSBuild变量,它是$(_ResourceNameInMainAssembly)

然而,解释为什么更难,我没有看到它可能是空的任何情况。 使用文本编辑器查看C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.WinFx.targets。 分配变量的文件部分如下所示:

  <_resourcenameinmainassembly Condition="'$(UICulture)' == ''">$(AssemblyName).g.resources <_resourcenameinmainassembly Condition="'$(UICulture)' != ''">$(AssemblyName).unlocalizable.g.resources 

该.targets文件长度为42567字节,在我的机器上的日期为06/06/12。 我确实安装了.NET 4.5。

作为一种解决方法,您可以将实际资源文件符号链接到“缺失” resources.resources文件。 我遇到了同样的问题并通过在提升的命令提示符下输入以下内容来修复它。

 mklink c:\MySolution\MyLibrary\MyLibrary\Properties\Resources.resources c:\MySolution\MyLibrary\MyLibrary\Properties\Resources.Designer.cs 

这是一个奇怪的。

我不知道是否有任何设置可以直接从IDE中调整,这可能会影响这种奇怪的行为。 检查命令行参数之后,就像你一样,我会弄脏手,并在一些文本编辑器中打开项目文件(例如记事本)。 在那里,我将检查所有节点,其中作为子元素,直到找到罪魁祸首。 您应该检查的其他文件是Properties文件夹中的* .resx文件。

希望能帮助到你。