sdk icon indicating copy to clipboard operation
sdk copied to clipboard

dotnet build fails to manage embedded resources

Open darkengines opened this issue 9 years ago • 15 comments

Steps to reproduce

Create a new class library project (under VS2017, last update) Add a Foo.resx file (with designer) Add a Foo.fr.resx file Go to the project directory Execute dotnet build

Expected behavior

The project must be built without error

Actual behavior

C:\Program Files\dotnet\sdk\1.0.0\Microsoft.Common.CurrentVersion.targets(4072,5): error MSB3030: Could not copy the file "obj\Debug\fr\ProjectName.resources.dll" because it was not found. [C:\Projects\SolutionName\ProjectName\ProjectName.csproj]

Environment data

dotnet --info output:

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.0 (tested with 1.0.1 as well)

darkengines avatar Mar 21 '17 15:03 darkengines

I am seeing the same error, only if the class library project has *.resx files with the language code in path.

For example: A class library with a resource file named Foo.fr.resx will fail. However a class library with a resource file named Foo.resx (without the .fr or any other language code) will compile without error.

dotnet --info

.NET Command Line Tools (1.0.3)

Product Information:
 Version:            1.0.3
 Commit SHA-1 hash:  37224c9917

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.3

orcnz avatar May 05 '17 04:05 orcnz

Try with MSBuild15 : MSBuild.exe /t:package

darkengines avatar May 10 '17 00:05 darkengines

I experience the same problem. It appears to be only a problem if you use the old csproj format.

If you move your resource files to a class library with the new csproj format, this might be a viable workaround.

mbp avatar Jun 17 '17 19:06 mbp

I confirm.

darkengines avatar Jun 17 '17 19:06 darkengines

I'm having this problem on Mac OS with Visual Studio 2017, trying to run from the command line.

eltiare avatar Sep 03 '17 18:09 eltiare

The originally reported issue persists in dotnet 2.0.0. In our case, I'm stuck using the old csproj format because Telerik Reporting tools don't yet support the new project file format.

I'd like to request that this issue be reopened.

desmondgc avatar Oct 02 '17 17:10 desmondgc

The dotnet command line does not support old style csproj project files.

livarcocc avatar Oct 02 '17 17:10 livarcocc

@livarcocc dotnet build also seems to have problems with embedded resources in general, also in new style csproj project files. In the attached project (a console application), I:

  • Access the embedded resource via resources, and print it in the console
  • Access the embedded resource via the manifest resource stream, and print it in the console

For your convenience, just run buildandrun.bat, and it will build and run using dotnet build. On my machine, this shows that the first way (accessing the embedded resource via Resources) does not work using dotnet build. Strangely enough, it does work when building the project in Visual Studio.

I see other changes in behaviour as well (numerically), but will create a separate post for this. [Edit: numerical differences were solved by forcing the platform to be x64 in the test settings file - appears to be the case that dotnet test or vstest.console by default (on Windows) runs in 32-bit modes].

EmbeddedResourceApp.zip

rlordcardano avatar Nov 10 '17 09:11 rlordcardano

Encountering this same thing -- works great in VS, but my CI builds are failing. Using dotnet build/dotnet test

Oceanswave avatar Dec 29 '17 14:12 Oceanswave

@rlordcardano your sample is using advanced resx features that aren't supported using the .net core versions of MSBuild. The core version only supports key-value strings in resx files.

The following part of your resx file isn't going to work using the cli:

<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Embedded" type="System.Resources.ResXFileRef, System.Windows.Forms">
  <value>..\Embedded.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>

There are a few issues for this and similar issues on the MSBuild side: https://github.com/Microsoft/msbuild/issues/2221 https://github.com/Microsoft/msbuild/issues/1247 https://github.com/Microsoft/msbuild/issues/2272

dasMulli avatar Dec 30 '17 10:12 dasMulli

@Oceanswave check if your resx files use any System.Windows.Forms references like mentioned above. If they contain anything but strings, the cli won't work and you'll have to use full msbuild from either a VS installation on windows or a recent mono version.

dasMulli avatar Dec 30 '17 10:12 dasMulli

@desmondgc I want to know if Telerik report designer works with the new msbuild csproj template?

buddalasunil999 avatar May 08 '18 09:05 buddalasunil999

bump

ghost avatar Jan 17 '19 22:01 ghost

I experience the same problem. It appears to be only a problem if you use the old csproj format.

If you move your resource files to a class library with the new csproj format, this might be a viable workaround.

@mbp what do you mean with this? Could you give me an example please?

auserx avatar Feb 27 '19 10:02 auserx

@dasMulli , So could u pls recommend which docker image is used for that kind of issue? Now I am using window server core image and I got this issue and my resx file is exactly the same u provided structure.

Lwin-Hope avatar Jul 17 '20 10:07 Lwin-Hope