2013-07-19 36 views
1

每當我試圖編譯在VS2012任何WPF項目我有以下的編譯錯誤:錯誤讀取資源文件的任何WPF項目在VS2012

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

問題是,當VS產生CSC的命令,它包含一個額外的部分複製/資源參數是這樣的:

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

CSC看起來只在第一個參數,因爲沒有文件名指定它拋出的錯誤。我進入了命令行模式,並在沒有額外參數的情況下進行測試,並驗證它是問題所在。我不想手動編譯我的項目!

任何人都知道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在項目文件:

<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> 
+0

順便說一句,我試着卸載Visual Studio並重新安裝。根本沒有效果。 – Jeff

回答

4

這不是一個額外的說法,它是一個不完整的。您通常會在此處看到/resource:obj\Debug\MyAppName.g.resources。有些東西會使文件名評估爲空字符串。它是從應用程序中的.xaml文件生成的。

工具+選項,項目和解決方案,構建和運行,「MSBuild項目生成輸出詳細」設置,將其更改爲詳細。您現在將獲得構建步驟的詳細跟蹤。將其複製/粘貼到記事本中,然後打開格式+文字自動換行功能,以便查看所有內容。

預期構建步驟,生成的文件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> 

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

這.targets文件是42567個字節長,我的機器上的日期是06/06/12。我確實安裝了.NET 4.5。

+0

我看起來有點不同。我已將它添加到上面的問題描述中。它看起來像我正在試圖從CSC命令早前遇到的不完整參數生成文件。 – Jeff

+1

是的,這個錯誤在那個確切的步驟,相同的基本問題。 .baml輸入文件生成正確。但$(_ResourceNameInMainAssembly)變量是一個空字符串。這很難解釋,它被分配在C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.WinFx.targets中,並且沒有任何情況可以看到它會將其留空。查看該文件並搜索名稱。將文件的日期/大小與另一臺計算機上的文件進行比較。 –

+0

就是這樣。 WinFx.targets文件中缺少以下代碼行:<_ResourceNameInMainAssembly Condition =「'(UICulture)'==''」> $(AssemblyName).g.resources Jeff

0

這是一個奇怪的一個。

我不知道是否有任何設置,你可以直接從IDE擺弄,這可能會影響這種奇怪的行爲。像你一樣檢查命令行參數後,我會弄髒自己的手,並在一些文本編輯器(例如記事本)中打開項目文件。在那裏,我會檢查所有的<ItemGroup>節點,其中<EmbeddedResource><Content Include="Something">作爲子元素,直到找到罪魁禍首。您應該檢查的其他文件是* .resx中的屬性文件夾。

希望它有幫助。

+0

項目文件是VS創建的默認文件。 (項目本身MyAppName是一個全新的空WPF項目,因爲我所有的WPF項目都顯示這個錯誤,所以我認爲最好用一個簡單的/新項目進行調試。)僅僅因爲它是默認的,並不意味着它不會自動生成基於一些錯誤配置的錯誤,我想我還有其他地方。我已將相關部分添加到上述問題描述中。有沒有什麼是我沒有看到的問題? – Jeff

+1

這可能與其他有類似錯誤但用途不同的其他用戶有關。我在其他帖子上看到過這樣的答案,它似乎幫助了其他用戶。我想我的投票把它留在這裏。謝謝 – Jeff

1

作爲解決方法,您可以將您的實際資源文件符號鏈接到「丟失」resources.resources文件。我遇到了同樣的問題,只需在提升的命令提示符中輸入以下內容即可解決問題。

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