phmonte / Buildalyzer

A utility to perform design-time builds of .NET projects without having to think too hard about it.
MIT License
605 stars 95 forks source link

Build with generated code #185

Closed bernd5 closed 7 months ago

bernd5 commented 3 years ago

Hello,

with net 6.0 we get generated code by default (implicit global usings). I would like to load those generated files with Buildalyzer, too.

What should I do?

slang25 commented 3 years ago

I understand that the latest previews for .NET 6 require an opt-in in the project file (certainly for preview 7), so you would need to add:

<ImplicitUsings>enable</ImplicitUsings>

that said, it should still work, as it shells out to msbuild. So if it works for you with your current SDK, buildalyzer should pick that up and get you some results that match what you are seeing in your IDE / command line.

Update: wrong - It's rc1 that will require the opt-in

bernd5 commented 3 years ago

In the new templates these implicit usings are enabled by default. I created a test pr with a helloWorld sample without touching the csproj file. The test fails currently.

slang25 commented 3 years ago

I've ran the test locally here, and it fails due to a weird error, which is the same error I see on all my projects (whatever TFM):

Could not copy the file apphost.exe

I'm not sure why, but when the .NET 6 SDK is present (i.e. installed and not suppressed by a global.json file) then the error crops up. I can work around like this:

System.Environment.SetEnvironmentVariable("UseAppHost", "false");

When I add that to the tests, your TestUsing project compiles successfully. cc @daveaglick

slang25 commented 3 years ago

Potential fix: https://github.com/daveaglick/Buildalyzer/pull/187

phmonte commented 7 months ago

Merge of solution accomplished