简体   繁体   English

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

[英]Error Reading Resource File for any WPF Project in VS2012

Whenever I try to compile any WPF project in VS2012 I have the following compile error: 每当我尝试在VS2012中编译任何WPF项目时,都会出现以下编译错误:

Error reading resource file 'c:\\Users\\mysuerID\\Documents\\Visual Studio 2012\\Projects\\MyAppNAme\\MyAppNAme\\obj\\Debug\\' -- 'The system cannot find the path specified. 读取资源文件'c:\\ Users \\ mysuerID \\ Documents \\ Visual Studio 2012 \\ Projects \\ MyAppNAme \\ MyAppNAme \\ obj \\ Debug \\时出错-'系统找不到指定的路径。 ' C:\\Users\\mysuerID\\Documents\\Visual Studio 2012\\Projects\\MyAppNAme\\MyAppNAme\\CSC MyAppNAme 'C:\\ Users \\ mysuerID \\ Documents \\ Visual Studio 2012 \\ Projects \\ MyAppNAme \\ MyAppNAme \\ CSC MyAppNAme

The problem is when VS generates the CSC command it contains an extra partial duplicated /resource parameter like this: 问题是当VS生成CSC命令时,它包含一个额外的部分重复的/ resource参数,如下所示:

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

CSC looks only at the first parameter and since no file name is specified it throws the error. CSC仅查看第一个参数,并且由于未指定文件名,因此会引发错误。 I went to command line mode and tested with and without the extra parameter and verified it is the problem. 我进入命令行模式,并在有无附加参数的情况下进行了测试,并验证了这是问题所在。 I don't want to have to manually compile my projects! 我不需要手动编译项目!

Anyone know how VS comes up with these parameters and how I could get rid of this extra invalid parameter? 任何人都知道VS是如何提出这些参数的,以及如何摆脱这个多余的无效参数?

The Build Output Looks Like this (Framework 4.5) 构建输出看起来像这样(框架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.

The ItemGroup in the Project File: 项目文件中的ItemGroup:

  <ItemGroup>
    <Compile Include="Properties\AssemblyInfo.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
    <None Include="app.config" />
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <AppDesigner Include="Properties\" />
  </ItemGroup>

It is not an extra argument, it is an incomplete one. 这不是一个多余的论点,而是一个不完整的论点。 You'd normally expect to see /resource:obj\\Debug\\MyAppName.g.resources there. 通常,您通常希望在那里看到/resource:obj\\Debug\\MyAppName.g.resources。 Something makes that filename evaluate to an empty string. 使文件名评估为空字符串的某种方式。 It is generated from the .xaml files in your app. 它是从您应用程序中的.xaml文件生成的。

Tools + Options, Projects and Solution, Build and Run, "MSBuild project build output verbosity" setting, change it to Detailed. 在“工具+选项”,“项目和解决方案”,“构建和运行”,“ MSBuild项目构建输出详细程度”设置下,将其更改为“详细”。 You'll now get a very detailed trace of the build steps. 现在,您将获得有关构建步骤的非常详细的跟踪。 Copy/paste it into Notepad and turn on Format + Word Wrap so you can see everything. 将其复制/粘贴到记事本中,然后打开“格式+自动换行”,以便您可以看到所有内容。

The expected build step that generates the MyAppName.g.resources file look like this: 生成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'.

Compare it with yours and tell us what you see different. 将其与您的进行比较,并告诉我们您看到的不同之处。


UPDATE: clearly this build step goes wrong for the exact same reason. 更新:显然,由于完全相同的原因,此构建步骤出错了。 The input file is generated correctly. 输入文件已正确生成。 I can narrow it down to a MSBuild variable that has an empty string, it is $(_ResourceNameInMainAssembly) . 我可以缩小到一个包含空字符串的MSBuild变量,它是$(_ResourceNameInMainAssembly)

Explaining why is much harder however, I don't see any scenario where it could be empty. 但是,解释为什么要困难得多,我看不到任何可能为空的情况。 Use a text editor to look at C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Microsoft.WinFx.targets. 使用文本编辑器查看C:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ Microsoft.WinFx.targets。 The part of the file that assigns the variable looks like this: 文件中分配变量的部分如下所示:

 <_ResourceNameInMainAssembly Condition="'$(UICulture)' == ''">$(AssemblyName).g.resources</_ResourceNameInMainAssembly>

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

That .targets file is 42567 bytes long and is dated 06/06/12 on my machine. 该.targets文件的长度为42567字节,在我的计算机上的日期为12/06/06。 I do have .NET 4.5 installed. 我确实安装了.NET 4.5。

As a workaround you can symlink your actual resources file to the "missing" resources.resources file. 解决方法是,可以将实际资源文件符号链接到“缺少的” resources.resources文件。 I ran into the same problem and fixed it by simply typing the following in to an elevated command prompt. 我遇到了同样的问题,只需在提升的命令提示符下键入以下内容即可解决此问题。

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

That's an odd one. 真奇怪。

I don't know if there are any settings that you can fiddle with directly from the IDE which could affect this bizarre behavior. 我不知道是否有任何设置可以直接从IDE中进行调整,而这可能会影响这种奇怪的行为。 After checking the command-line parameters, as you did, I would get my hands dirty and open the project file in some text editor (like notepad, for instance). 在检查了命令行参数之后,就像您所做的那样,我会弄脏双手,然后在某些文本编辑器(例如,记事本)中打开项目文件。 There I would check all the <ItemGroup> nodes with an <EmbeddedResource> or <Content Include="Something"> as child elements until the culprit is found. 在那里,我将使用<EmbeddedResource><Content Include="Something">作为子元素来检查所有<ItemGroup>节点,直到找到罪魁祸首。 Other files you should check are the *.resx ones in the Properties folder. 您应检查的其他文件是“ 属性”文件夹中的* .resx文件。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM