错误读取资源在VS2012文件中的任何WPF项目 [英] Error Reading Resource File for any WPF Project in VS2012

查看:620
本文介绍了错误读取资源在VS2012文件中的任何WPF项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试编译在VS2012我有以下的编译错误的WPF项目:




错误读取资源文件'C:\\ \\Users\mysuerID\Documents\Visual工作室
2012\Projects\MyAppNAme\MyAppNAme\obj\Debug\ - 系统无法
找不到指定的路径。 C:\Users\mysuerID\Documents\Visual工作室
2012\Projects\MyAppNAme\MyAppNAme\CSC MyAppNAme




问题是,当VS产生CSC的命令,它包含了这样一个额外的部分重复/资源参数:

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

CSC看起来只在第一个参数,因为没有文件名指定它抛出的错误。我去命令行模式和有和没有额外的参数测试和验证它是问题所在。我不希望有手动编译我的项目!



任何人都知道如何VS自带了这些参数,我怎么能摆脱这种额外的参数无效的?



生成输出看起来像这样(框架4.5)

  1> ;目标MainResourcesGeneration文件C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets从项目的C:\Users\jws15592\Documents\ Visual Studio的2012\Projects\MyAppName\MyAppName\MyAppName.csproj(目标PrepareResources依赖于它):
1 GT;建筑目标MainResourcesGeneration的问题。
1 GT;输入文件C:\Users\jws15592\Documents\Visual工作室2012\Projects\MyAppName\MyAppName\obj\Debug\MainWindow.baml比输出新文件obj\Debug\。
1 GT;任务消息跳过,由于假条件; ('$(MSBuildTargetsVerbose)'=='真')的评价为(''=='真')。
1>使用汇编ResourcesGenerator任务PresentationBuildTasks,版本= 4.0.0.0,文化=中性公钥= 31bf3856ad364e35。
1 GT;任务ResourcesGenerator
1 GT;
1 GT;
1 GT;微软(R)建设任务ResourcesGenerator'版本'4.0.30319.17929通过内置:FX45RTMREL。
1 GT;版权所有(c)Microsoft公司2005年保留所有权利。
1 GT;
1 GT;
1 GT;生成.resources文件:obj\Debug\'...
1 GT; C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets(709, 5):错误RG1000:未知的生成错误,找不到路径的一部分C:\Users\jws15592\Documents\Visual工作室2012\Projects\MyAppName\MyAppName\obj\ '。'Debug\
1 GT;完成执行任务ResourcesGenerator - 失败。
1 GT;完成项目建设目标MainResourcesGenerationMyAppName.csproj - 失败。



的ItemGroup在项目文件:

 <&的ItemGroup GT; 
<编译包括=Properties\AssemblyInfo.cs>
<亚型GT;代码< /亚型GT;
< /编译>
<编译包括=Properties\Resources.Designer.cs>
<&AUTOGEN GT;真< / AUTOGEN>
< D​​esignTime>真< / DesignTime>
< D​​ependentUpon> Resources.resx< / DependentUpon>
< /编译>
<编译包括=Properties\Settings.Designer.cs>
<&AUTOGEN GT;真< / AUTOGEN>
< D​​ependentUpon> Settings.settings< / DependentUpon>
< D​​esignTimeSharedInput>真< / DesignTimeSharedInput>
< /编译>
< EmbeddedResource包括=Properties\Resources.resx>
<发生器GT; ResXFileCodeGenerator< /发电机>
< LastGenOutput> Resources.Designer.cs< / LastGenOutput>
< / EmbeddedResource>
<无包括=的app.config/>
<无包括=Properties\Settings.settings>
<发生器GT; SettingsSingleFileGenerator< /发电机>
< LastGenOutput> Settings.Designer.cs< / LastGenOutput>
< /无>
< AppDesigner包括=Properties\/>
< /&的ItemGroup GT;


解决方案

这不是一个的额外的的说法,这是一个不完整的。你通常希望看到/resource:obj\Debug\MyAppName.g.resources那里。东西使得该文件名评价为空字符串。它是从你的应用程序中的.xaml文件生成的。



工具+选项,项目和解决方案,构建和运行,MSBuild项目生成输出的详细程度设置,更改要详细。现在,您将得到的构建步骤非常详细的跟踪。复制/粘贴到记事本,然后打开格式+自动换行,所以你可以看到一切。



有望的生成步骤产生的MyAppName。 g.resources文件是这样的:

  1 GT;输出文件obj\Debug\MyAppName.g.resources呢不存在。 
1 GT;任务消息跳过,由于假条件; ('$(MSBuildTargetsVerbose)'=='真')的评价为(''=='真')。
1>使用汇编ResourcesGenerator任务PresentationBuildTasks,版本= 4.0.0.0,文化=中性公钥= 31bf3856ad364e35。
1 GT;任务ResourcesGenerator
1 GT;
1 GT;
1 GT;微软(R)建设任务ResourcesGenerator'版本'4.0.30319.17929通过内置:FX45RTMREL。
1 GT;版权所有(c)Microsoft公司2005年保留所有权利。
1 GT;
1 GT;
1 GT;生成.resources文件:obj\Debug\MyAppName.g.resources'...
1 GT;读取资源文件:C:\Users\hpass_000\AppData\Local\Temporary Projects\MyAppName\obj\Debug\MainWindow.baml......
1 GT;资源ID为mainwindow.baml。
1 GT;生成的.resources文件:obj\Debug\MyAppName.g.resources。



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






更新:很明显,这个构建步骤出错的确切同样的原因。输入文件正确生成。我可以缩小它具有一个空字符串的MSBuild的变量,它是 $(_ ResourceNameInMainAssembly)



在解释为什么要困难得多不过,我没有看到任何场景,它可能是空的。使用文本编辑器来查看C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets。来分配变量的文件的部分看起来是这样的:

 < _ResourceNameInMainAssembly条件='$(的UICulture)'= =''> $(的AssemblyName).g.resources< / _ ResourceNameInMainAssembly> 

< _ResourceNameInMainAssembly条件='$(的UICulture)'=''!> $(的AssemblyName).unlocalizable.g.resources< / _ ResourceNameInMainAssembly>

这.targets文件是42567字节长,我的机器上的日期是06/06/12。我有.NET 4.5安装。


Whenever I try to compile any WPF project in VS2012 I have the following compile error:

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\CSC MyAppNAme

The problem is when VS generates the CSC command it contains an extra partial duplicated /resource parameter like this:

/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. 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?

The Build Output Looks Like this (Framework 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>
    <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. Something makes that filename evaluate to an empty string. It is generated from the .xaml files in your app.

Tools + Options, Projects and Solution, Build and Run, "MSBuild project build output verbosity" setting, change it to Detailed. 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:

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).

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. 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. I do have .NET 4.5 installed.

这篇关于错误读取资源在VS2012文件中的任何WPF项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆