ThisAssembly icon indicating copy to clipboard operation
ThisAssembly copied to clipboard

Source Generator doesn't work anymore with .NET 6.0.200 SDK

Open maxkatz6 opened this issue 2 years ago • 8 comments

Describe the Bug

I have latest 6.0.200 SDK installed from dotnet/installer repository. Note this version is not yet available to be installed from MS web site. So this issue might not be reproducible when this SDK version will be officially released on stable channel, if they fix something before.

Steps to Reproduce

  1. Install 6.0.200 SDK from dotnet/installer repository
  2. dotnet new console
  3. Reference <PackageReference Include="ThisAssembly.Constants" Version="1.0.9" />
  4. Add simple constant to be generated <Constant Include="Foo.Bar" Value="Baz" />
  5. dotnet build

Expected Behavior

It works, constant is generated.

Exception with Stack Trace

maxkatz6@mak-kat-mb thisassembly-test % dotnet build
Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /Users/maxkatz6/repos/thisassembly-test/thisassembly-test.csproj (in 290 ms).
CSC : error CS2001: Source file '/Users/maxkatz6/repos/thisassembly-test/Foo.Bar' could not be found. [/Users/maxkatz6/repos/thisassembly-test/thisassembly-test.csproj]

Build FAILED.

CSC : error CS2001: Source file '/Users/maxkatz6/repos/thisassembly-test/Foo.Bar' could not be found. [/Users/maxkatz6/repos/thisassembly-test/thisassembly-test.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.79

Version Info

ThisAssembly.Constants version 1.0.9 .NET SDK version 6.0.200:

maxkatz6@mak-kat-mb thisassembly-test % dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.200
 Commit:    f13c273745

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.200/

Host (useful for support):
  Version: 6.0.1
  Commit:  3a25a7f1cc

.NET SDKs installed:
  3.1.416 [/usr/local/share/dotnet/sdk]
  6.0.200 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.21 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.21 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.22 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Additional Info

Bin log: msbuild.binlog.zip

maxkatz6 avatar Feb 10 '22 01:02 maxkatz6

Also can confirm that it works as expected with installing 6.0.102 SDK and specifying it in global.json:

{
    "sdk": {
      "version": "6.0.102"
    }
}
maxkatz6@mak-kat-mb thisassembly-test % dotnet build    

Welcome to .NET 6.0!
---------------------
SDK Version: 6.0.102

Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /Users/maxkatz6/repos/thisassembly-test/thisassembly-test.csproj (in 267 ms).
  thisassembly-test -> /Users/maxkatz6/repos/thisassembly-test/bin/Debug/net6.0/thisassembly-test.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.28

maxkatz6 avatar Feb 10 '22 01:02 maxkatz6

Sadly this issue is reproducible with stable release of this SDK. At least on mac.

maxkatz6 avatar Feb 18 '22 07:02 maxkatz6

Even worse, this isn't even specific to ThisAssembly. I get the same errors with xunit:

CSC : error CS2001: Source file '/home/runner/work/ThisAssembly/ThisAssembly/src/ThisAssembly.Tests/.xunit.runner.visualstudio.dotnetcore.testadapter' could not be found. [/home/runner/work/ThisAssembly/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
CSC : error CS2001: Source file '/home/runner/work/ThisAssembly/ThisAssembly/src/ThisAssembly.Tests/.xunit.runner.reporters.netcoreapp10' could not be found. [/home/runner/work/ThisAssembly/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
CSC : error CS2001: Source file '/home/runner/work/ThisAssembly/ThisAssembly/src/ThisAssembly.Tests/.xunit.runner.utility.netcoreapp10' could not be found. 

kzu avatar Feb 22 '22 15:02 kzu

Can we help resolving this?

nikeee avatar Mar 02 '22 15:03 nikeee

I can confirm it works when using 6.0.103. 6.0.200 did not work, as well as 6.0.201.

So it is most likely a problem with the .NET SDK that is shipping with the VS 2022 Preview.

nikeee avatar Mar 08 '22 22:03 nikeee

We made a change in 6.0.200 that compares the contents of additional files to see if they have changed. This is part of the work to enable an in-server cache for VBCSCompiler which should make command line builds that use generators faster.

Unfortunately we didn't consider the case where the additional files didn't exist (or were binary which caused a different exception) so we backed the change out (https://github.com/dotnet/roslyn/pull/59776) and things should be working in 6.03xx previews again. We'll ensure we consider these scenarios in the future.

That being said, this is sort of abusing AdditionalFiles as a way of getting metadata into the generator. That's a scenario I don't think can be achieved today without doing this, but I'll open an issue to track coming up with a better API for this.

chsienki avatar Apr 05 '22 23:04 chsienki

@chsienki thanks for the information! I guess I can close this issue after 6.0.300 released.

maxkatz6 avatar Apr 06 '22 00:04 maxkatz6

I have the feeling it resumed working with SDK 6.0.202 / .NET 6.0.4

Edit 2022-04-26: Building (inside VS) seems to work now but dotnet publish on CI side does not.

springy76 avatar Apr 21 '22 12:04 springy76

Yes, I believe things are working again now. Please do reopen if that's not the case.

kzu avatar Sep 04 '22 23:09 kzu