msbuild: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.
This issue has been reported before, I believe here : https://github.com/dotnet/msbuild/issues/2221
However unlike presented in this thread, it still appears past versions 16.3+ of MSBuild. I’m personally running Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Issue Description
My windows form app can be built successfully using Visual Studio 2019, but:
- Cannot be built with dotnet msbuild from command line
- Cannot be built with dotnet publish from command line
- Cannot be built with “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe” from command line.
Steps to Reproduce
Here are the arguments I used for all three of them:
-target:Publish /p:Configuration=Release /p:GenerateResourceUsePreserializedResources=True /p:OutDir="../Build"
Expected Behavior
The app builds successfully to the target folder.
Actual Behavior
All three of them output some version of the following text:
error MSB3822: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references. [my.csproj]
However, none of my .resx in my windows form project have any image. Only one contains non-string content, of the following nature:
The other .resx i have seems to be doing fine without any non-string resource, but not this one - deleting these elements lead to malfunction.
Moreover, if I do try to embed the “System.Resources.Extensions” that is being mentioned here, my app does build, but said window cannot be opened.
<PackageReference Include="System.Resources.Extensions" Version="4.7.1" />
Analysis
Tried every version of System.Resources.Extensions from the top, the application seems to work correctly with <PackageReference Include="System.Resources.Extensions" Version="4.6.0" />
for reasons unknown to me.
This is still not a good solution. I feel like I shouldn’t have to include this undesired library.
Versions & Configurations
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Windows 10 running Microsoft Visual Studio 2019
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 29 (17 by maintainers)
Hi used NuGet Package Manager GUI in Visual Studio 2022.
I must have found myself here a dozen times or more by now.
I think there is a bug when building using
dotnet
where this error is generated even when building a .NET Framework project.My command is:
and I have conditional
ItemGroup
andPropertyGroup
tags that have the necessary tags:<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
and
<PackageReference Include="System.Resources.Extensions" Version="4.7.0" />
when building for .netcoreapp3.1
but I get the error even when building for .NET 4, where these shouldn’t be required afaik (and in fact, can’t be used I think).