Repository navigation
Description
We have a few projects that muti target .net core and the old fashioned .net framework. Some of these include binary resources (mostly images). With .net core 2.1 / 2.2 they build successfully but accessing an image while running under .net core throws an exception while with the full framework everything continues to works.
Now .net core 3.0 added support for binary resources giving us the chance to eliminate a few workarounds.
But now TargetFramework=net48 fails to build. As we are still in the transition to .net core and most of our products (still) require the full framework. Therefore this blocks any usage of .net core 3.0 in our codebase.
Steps to reproduce
unzip the attached project and run "dotnet build" or "dotnet build -p:TargetFramework=net48". Note that "dotnet build -p:TargetFramework=netcoreapp3.0" builds successfully.
Expected behavior
Successful build - net48 definitely supports images inside .resx
Actual behavior
Microsoft (R)-Build-Engine, Version 16.3.0-preview-19426-01+faf5e5d75 f▒r .NET Core
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
Wiederherstellung in "113,4 ms" f▒r "C:\source\ResxBug\LibraryWithImage\LibraryWithImage.csproj" abgeschlossen.
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
C:\Program Files\dotnet\sdk\3.0.100-preview9-014004\Microsoft.Common.CurrentVersion.targets(3056,5): error : MSB3823: Non-string resources require the property GenerateResourceUsePreserializedResources to be set to true. [C:\source\ResxBug\LibraryWithImage\LibraryWithImage.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview9-014004\Microsoft.Common.CurrentVersion.targets(3056,5): warning MSB3555: Die Ausgabedatei "C:\source\ResxBug\LibraryWithImage\obj\Debug\net48\LibraryWithImage.Resources.resources" ist m▒glicherweise besch▒digt. [C:\source\ResxBug\LibraryWithImage\LibraryWithImage.csproj]
LibraryWithImage -> C:\source\ResxBug\LibraryWithImage\bin\Debug\netcoreapp3.0\LibraryWithImage.dll
Fehler beim Buildvorgang.
C:\Program Files\dotnet\sdk\3.0.100-preview9-014004\Microsoft.Common.CurrentVersion.targets(3056,5): warning MSB3555: Die Ausgabedatei "C:\source\ResxBug\LibraryWithImage\obj\Debug\net48\LibraryWithImage.Resources.resources" ist m▒glicherweise besch▒digt. [C:\source\ResxBug\LibraryWithImage\LibraryWithImage.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview9-014004\Microsoft.Common.CurrentVersion.targets(3056,5): error : MSB3823: Non-string resources require the property GenerateResourceUsePreserializedResources to be set to true. [C:\source\ResxBug\LibraryWithImage\LibraryWithImage.csproj]
1 Warnung(en)
1 Fehler
Verstrichene Zeit 00:00:02.58
Environment data
SDK 3.0.100-preview9-014004 installed using the installer (see https://dotnet.microsoft.com/download/dotnet-core/3.0 )
Activity
rainersigwald commentedon Sep 9, 2019
This is an intentional change with .NET Core SDK 3.0. As you point out, the prior versions of MSBuild on .NET Core would produce corrupted output which would crash at runtime. With the new version, it's possible to embed resources when using .NET Core MSBuild, but because they're embedded in a different way, they require a new reference to access them at runtime:
System.Resources.Extensions. This is available as a NuGet package which will be published to NuGet.org when .NET Core 3.0 is released. It's available now from a prerelease feedhttps://dotnetfeed.blob.core.windows.net/dotnet-core/index.json.to-st commentedon Sep 10, 2019
just to make sure: It is intentional that if you have a project with the new csproj format, binary resources, a PackageReference to System.Resources.Extensions and add net48 as targetframework it won't built using "dotnet build"?
I do not complain that netcoreapp2.1 no longer builds broken dll ;)
I assume support for binary resources in net48 is not dropped altogether, so how should I build a project with the new csproj format for net48? Calling the msbuild from the .net framework build tools directly?
rainersigwald commentedon Sep 10, 2019
Correct.
Yes: projects built using Visual Studio or
MSBuild.exe(as opposed todotnet buildordotnet msbuild) use the older approach to serialize resources into the output assembly by default. It's not ideal to have the project built two different ways depending on how you launched the build, though, so I would recommend always specifyingGenerateResourceUsePreserializedResources=truein your projects and referencingSystem.Resources.Extensions. That unifies on the new codepath.RusKnyaz commentedon Oct 3, 2019
I did not quite understand. What if I just want my existing project to build successfully both on machines with netcore2.1 and on machines with netcore3.0? However, I do not want to change anything, and am ready to get resources through Assembly.GetManifestResourceStream.
RusKnyaz commentedon Oct 3, 2019
I solved my issue by removing of the extra lines from Resources.resx file.
rainersigwald commentedon Oct 3, 2019
If your projects built successfully with the .NET Core SDK 2.1, they should work without modification in .NET Core SDK 3.0. If the projects built without errors but produced corrupt outputs in 2.1, they can be built correctly only with 3.0's new behavior.
figloalds commentedon Oct 9, 2019
I got mad too and I was about to just rage uninstall dotnet sdk 3.0, but then it was just add
<PackageReference Include="System.Resources.Extensions" Version="4.6.0" />to references and
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>to a property group
I have a few complaints though: GenerateResourceUsePreserializedResources is a HUGE and ugly name and also I wonder why and who would ever disable this, if it's the only way to get embed resources in SDK 3.0 to build?
It looks unnecessary to add that ugly bigass name property to my csproj and the error message could have been: Hey, you just need to install System.Resources.Extensions from NuGet, we'll make the rest work.
This over here is one of my biggest rants with .Net lately: Things keep breaking every time you upgrade the SDK. :\
figloalds commentedon Oct 11, 2019
Actually after I applied the fixes suggested NOW the application causes runtime error with
Unable to load file or assembly 'System.Resources.Extensions, Version=4.0.0I'm uninstalling SDK 3.0 because it's causing a lot more problems than it should it Installed automatically with Visual Studio update and just broke a lot of code that used to work fine when building with dotnet cli 2.2.300 and even after trying to apply the changes suggested by the SDK it still caused more problems.
Edit: except it's not possible without removing the entire Web Development from Visual Studio altogether. So because of a broken update on Visual Studio I have to completely remove non-string resources from projects because my dotnet command will just build broken assemblies otherwise.
Edit 2: Fixed by going to
C:\Program Files\dotnet\sdkand hardcore deleting 3.0.100;RDMPDEV-1665 Fixed `dotnet build` failing on machines with netcore3.0…
MiguelAlho commentedon Jan 8, 2020
Also noticed this fix won't work when targeting net45, since the System.Resources.Extensions package does not support it (minimum is netstandard2.0 which would be net461). I know net45 is old, but this app is an installer intended to run on machines that might not have any new version of .Net running (but will install net48 if needed).
Remove COM reference for .NET Core (#6975)
Remove COM reference for .NET Core (Jackett#6975)
mikhail-barg commentedon Jan 30, 2020
@rainersigwald I just faced this issue, and while the fix with adding the package and setting the flag does work, it looks really weird that two build paths are actually different. Could this difference be mitigated or at least be transparently hidden from developers?
15 remaining items
Add configuration required to embedding pictures in the resources (#277)
HavenDV commentedon Nov 12, 2020
I am trying to release a version of a library for .Net Framework 4.5 besides .Net Core 3.1 and .Net 5, can you explain this in more detail?
Simple usage doesn't work:
PPenglis commentedon Nov 13, 2020
In your projects PropertyGroup set
If the other is still giving issues one could use GeneratePathProperty=true on the nuget package and then reference the dll directly:
HavenDV commentedon Nov 13, 2020
I am trying this. But the package does not contain anything suitable other than System.Resources.ResourceManager.dll.
Anyway, I get the same errors:
rainersigwald commentedon Nov 13, 2020
@HavenDV That was in reply to #4704 (comment) which reported some different issues. If you get this error
you need to add
to your project file.
rainersigwald commentedon Nov 13, 2020
@gooterz nit:
System.Resources.Extensionsis not in the reference assemblies, only its own package.HavenDV commentedon Nov 13, 2020
I'm looking for a way to add .Net 4.0 and .Net 4.5 targets to a multi-target project. .Net 4.6.1, .Net Core 3.1 and .Net 5 work fine.
rainersigwald commentedon Nov 13, 2020
@HavenDV Ah, I see. Since
System.Resources.Extensionsonly has .NET 4.6.1 and .NET Standard 2.0, it can't be used there. You can build a project that multitargets to older .NET versions withMSBuild.exe, but not withdotnet build.martingertsen commentedon Dec 16, 2021
@RusKnyaz
What extra line did you remove?
I'm having the same problem :-/
Luiz-Monad commentedon Dec 22, 2021
Do I really need to create the 'resources.resx' for embedded resources to work ? I presumed they would just work by setting them on the
.csproj. Is that the expected behavior ? can someone confirm it for me, please ?martingertsen commentedon Dec 22, 2021
I circumvented the problem by removing the reference to the
System.Resources.ExtensionNuGet package.To get the project to build after that, I had to set
GenerateResourceUsePreserializedResourcestofalse.This made the project work fine, though I lost the localized ressources in the generated NuGet.
I didn't find a solution for that, but fortunately I had just a few texts localized, so I changed to using a dictionary instead - suboptimal, I know, but after all this time consuming trial & error I was short on time, and I had to get a working solution fast, so yeah... this is where I ended up :-/
Enable to build with dotnet
Setting GenerateResourceUsePreserializedResources for the projects th…
chuongmep commentedon Feb 3, 2023
This problem still cause with .NET 6 Multi Platform