question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ProduceOnlyReferenceAssembly=true fails with `Do not use refout when using refonly`

See original GitHub issue

The 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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tannergoodingcommented, Apr 14, 2021

Something else in the build system now decided to specify the other one.

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.

0reactions
jcouvcommented, Jun 2, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found