ProduceOnlyReferenceAssembly=true fails with `Do not use refout when using refonly`
See original GitHub issueThe following project fails to compile:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<ProduceOnlyReferenceAssembly>true</ProduceOnlyReferenceAssembly>
</PropertyGroup>
</Project>
The above project will fail to compile with error
CSC : error CS8308: Do not use refout when using refonly.
This used to work with target netstandard2.0
instead.
The workaround is to set the following to false:
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
However it’s rather counter-intuitive that to generate a reference assembly - but only a reference assembly - you actually have to turn off producing a reference assembly.
It is likely related to this bit and explains why netstandard2.0 works but net5.0+ doesn’t: https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.TargetFrameworkInference.targets#L233
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right, the SDK added a new option specifying it by default for .NET 5+ (it’s the
Microsoft.NET.TargetFrameworkInference.targets
I linked a couple posts up).My suggested fix was one the SDK could take to ensure it remains correct by default if the user specifies
ProduceOnlyReferenceAssembly
as you did.Sounds like a good idea. I don’t see any impact on the compiler and this would make it easier to deal with the implicit default from the SDK.
Linking this issue to main ref assemblies umbrella issue: https://github.com/dotnet/roslyn/issues/2184