devlooped / ThisAssembly

Exposes project and assembly level information as constants in the ThisAssembly class using source generators powered by Roslyn.
https://clarius.org/ThisAssembly
MIT License
429 stars 24 forks source link

Source Generator no longer runs since updating to 2.0.0 #407

Open MagicAndre1981 opened 6 days ago

MagicAndre1981 commented 6 days ago

Describe the Bug

After Updating ThisAssembly to from 1.5.0 to 2.0.0 I can no longer access the ThisAssembly.Info properties like ThisAssembly.Info.Description

image

As they come from 3rd party tools, not from my project:

image

Steps to Reproduce

update from "ThisAssembly.AssemblyInfo" to 2.0:

<PackageReference Include="ThisAssembly.AssemblyInfo" Version="2.0.0">

Expected Behavior

code can be called var Description = ThisAssembly.Info.Description; fine as in 1.5.0

In my csproj I have set thoise 2 entries:

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>

and I no longer see the genereted ThisAssembly.AssemblyInfo.g.cs file only the ApplicationConfiguration.g.cs which includes the generated calls for ApplicationConfiguration.Initialize();

Back this issue Back this issue

kzu commented 6 days ago

Hi there! Some questions:

Thanks!

kzu commented 6 days ago

I created a new console app, added the package, and verified that the intellisense doesn't work at first, but after first build, it does. Seems to be something in VS since I'm not doing anything different on that front.

image

kzu commented 6 days ago

If you delete bin/obj without closing the source file, you see the same effect:

image

(note the Build + Intellisense in the drowdown). Doing a "full build" fixes it automatically though.

Does that match your experience?

MagicAndre1981 commented 6 days ago

closing/reopening make no different and also deleting the obj nuget folder makes no difference.

This is a compile error as the generated class is not found I can't compile the project at all no matter if I try it from VS2022 or cli with dotnet.

kzu commented 6 days ago

Could you share which package you're using? ThisAssembly.AssemblyInfo or ThisAssembly (metadata package)? Also, would you mind creating a blank console app, adding the same package and using WriteLine as I did above? If you see the same error, would you mind running dotnet build -bl and attaching the binlog? 🙏

MagicAndre1981 commented 6 days ago

I use this one:

https://www.nuget.org/packages/ThisAssembly.AssemblyInfo/2.0.0

and before updating I was using the 1.5.0 version which is now unlisted?

https://www.nuget.org/packages/ThisAssembly.AssemblyInfo/1.5.0

I'm now out of office for the rest of the day, I'll try to compare the build with 1.5.0 and 2.0.0 tomorrow.

kzu commented 6 days ago

Yeah, I have unlisted 1.5 in favor of 2.0.

MagicAndre1981 commented 5 days ago

ok, comparing 1.5.0 and 2.0.0 shows that 2.0.0 nuget misses the actual generator dll ThisAssembly.AssemblyInfo.dll and so this is no wonder why no code is generated. The thisassembly.constantspackage still contains the ThisAssembly.Constants.dll so consts are translated into code. 🤔 Why is the dll missing? What have you changed?

And I'm not allowed to provide such a binlog (GDPR).

MagicAndre1981 commented 5 days ago

Why is the dll missing? What have you changed?

ok, after looking at the commits (which are horrible as there are a lot of meaningless commits "Bump files with dotnet-file sync" which is awfull to see what commits do, you need to check every commit what is changed) I found this commit.

This explains the dependency on ThisAssembly.Constants and here is my issue. With MSBuild Structured Log Viewer I can see that the task to transfer my assembly infos into constants is not called so the Constants Source generator can only transfer my dummy constants I've added to check if this code generator is called.

image

kzu commented 4 days ago

ThisAssembly.AssemblyInfo is indeed just a special case of Contants (most packages are, now). That should not be the issue at all.

Could you please create a repro project? I simply cannot reproduce your issue as-is. The fact that those targets are greyed out do not indicate much (could have run previously already, for example). Without either a repro project or a binlog, there isn't much I can do :(

you need to check every commit what is changed

Not really, you can just look at commits that actually affect the specific project folder or files. dotnet-file sync keeps my template repo in sync only, which involves gh workflows, markdown text, and so on. Nothing in C# files in most cases.

MagicAndre1981 commented 3 days ago

I've created a demo that works fine with 1.5.0 and fails with 2.0.3. It is an empty .net 8 WinForms application but includes all reference nugets as in my real application but it depends on subversion for version control.

You need to checkout the code from the repo with svn/TortoiseSVN and open the sln in trunk

ThisAssembly.AssemblyInfo.Demo_SVN_Repo.zip

If I downgrade the package to 1.5.0 I get the generated files.

MagicAndre1981 commented 7 hours ago

Could you please create a repro project? I simply cannot reproduce your issue as-is.

Did you have some time to look at it? You need use svn checkout file:/// with path to create a working copy and get the project.