dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

SDK passes Microsoft.VisualBasic reference when using Embed option #10591

Open jaredpar opened 4 years ago

jaredpar commented 4 years ago

Repro steps:

  1. Create a new Visual Basic console application targeting netcoreapp3.1
  2. Set <VBRuntime>Embed</VBRuntime>
  3. Build and generate a binary log

The expectation here is that Microsoft.VisualBasic is not passed as a reference to the compilation. The actual behavior is that it is passed as a reference. Notice also if you change the target framework to netcoreapp2.1 or netstandard2.0 it is not passed as a reference.

This is making it hard to multi-target the Visual Basic compiler because our code is written with the expectation that the real runtime is not provided as a reference.

Related: https://github.com/dotnet/roslyn/issues/40766

nguerrera commented 4 years ago

Need some triage info.

Should we try to get this approved for 16.5 (3.1.200), or is 16.6 (3.1.300) ok? Or can you wait to adopt a 5.0 sdk to get unblocked on this?

Is there a customer scenario for Embed on .NET Core 3+ or is it more something particular to constraints of building VB compiler itself?

jaredpar commented 4 years ago

This can wait until 16.6. It's okay to keep MS.VB on netstandard2.0 for a while until this gets sorted out.

Is there a customer scenario for Embed on .NET Core 3+ or is it more something particular to constraints of building VB compiler itself?

More the latter. The compiler wants to be as dependency free as possible.

RikkiGibson commented 4 years ago

Since this issue requires us to single-target some of our projects to 'netstandard2.0', it ends up forcing us to build Microsoft.CodeAnalysis.CSharp among others in both netstandard2.0 and netcoreapp3.1 flavors in order to build a netcoreapp3.1 test project, which adds a significant bit of time to the inner loop of editing and rerunning tests.

It would be great if this could get fixed and we could multi-target "netcoreapp3.1;netstandard2.0" all the way down.

rainersigwald commented 4 years ago

Workaround:

  <Target Name="WorkAroundDotnetSdk10591"
          AfterTargets="ResolveTargetingPackAssets"
          Condition="'$(Language)' == 'VB' AND '$(VBRuntime)' == 'Embed'">
    <ItemGroup>
      <Reference Remove="@(Reference)" Condition=" '%(FileName)' == 'Microsoft.VisualBasic' or '%(FileName)' == 'Microsoft.VisualBasic.Core' " />
    </ItemGroup>
  </Target>

Works on a trivial library project.