1

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>
Jeff
  • 8,020
  • 34
  • 99
  • 157

3 Answers3

4

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Mine looks quite bit different. I've added it to the problem description above. It looks like mine is trying to generate the file from the incomplete parameter I came across in the CSC command earlier. – Jeff Jul 22 '13 at 14:28
  • 1
    Yup, this goes wrong at that exact step, same basic problem. The .baml input file is generated correctly. But the $(_ResourceNameInMainAssembly) variable is an empty string. That's very hard to explain, it is assigned in C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets and there's no scenario I can see that would leave it empty. Have a look at that file and search for the name. Compare the date/size of the file with one on another machine. – Hans Passant Jul 22 '13 at 14:56
  • That was it. The following line was missing from the WinFx.targets file: <_ResourceNameInMainAssembly Condition="'$(UICulture)' == ''">$(AssemblyName).g.resources – Jeff Jul 22 '13 at 16:23
  • 1
    Woot. Love to hear an explanation of how that happened :) – Hans Passant Jul 22 '13 at 16:30
1

As a workaround you can symlink your actual resources file to the "missing" resources.resources file. 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
pekkav
  • 113
  • 9
0

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. 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. Other files you should check are the *.resx ones in the Properties folder.

Hope it helps.

Leandro
  • 1,560
  • 17
  • 35
  • The project file is the default one created by VS. (The project itself MyAppName is a brand new empty WPF project. Since all my WPF projects show this error I thought it best to debug with a simple/new project.) Just because it's default though doesn't mean it didn't auto generate an error based on some mal-configuration I have somewhere else I suppose. I've added the relevant section to the problem description above. Is there something there that's a problem that I'm not seeing? – Jeff Jul 22 '13 at 14:24
  • 1
    It might be relevant for some other user with similar error, but different cause. I have seen answers like this on other posts and it seems to have helped other users. I guess my vote it to leave it here. Thanks – Jeff Jul 22 '13 at 16:25