Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Generator not installed for packages.config projects #62

Closed
riverar opened this issue Jan 24, 2021 · 7 comments · Fixed by #98
Closed

Source Generator not installed for packages.config projects #62

riverar opened this issue Jan 24, 2021 · 7 comments · Fixed by #98
Labels
bug Something isn't working

Comments

@riverar
Copy link

riverar commented Jan 24, 2021

Repro steps:

  1. Start Visual Studio 2019 (16.8.3)
  2. File > New > Project > Console App (.NET Framework), select framework .NET Framework 4.8, then click the Create button
  3. Add Microsoft.Windows.CsWin32 nuget prerelease package
  4. Add NativeMethods.txt file, with single line containing CreateFileW
  5. Rebuild
  6. Observe parent Microsoft.Windows namespace does not exist per documentation
@riverar
Copy link
Author

riverar commented Jan 24, 2021

Update: C# 9.0 requires .NET 5, so this will never work. The README is a bit misleading as it states (emphasis mine):

Source Generators require C# 9, which comes with the .NET 5 SDK or Visual Studio 2019 Update 8 (16.8).

This gave me the incorrect perception that Visual Studio shipped with a component that CsWin32 relied upon and would enable me to use this with .NET Framework projects.

I'm bummed out now, we can't use any of this stuff.

@riverar riverar changed the title Source generator doesn't appear to be running in VS2019/netfx console app Does not support .NET Framework 4.x projects Jan 24, 2021
@riverar riverar closed this as completed Jan 24, 2021
@AArnott
Copy link
Member

AArnott commented Jan 24, 2021

@riverar, this project does indeed support projects targeting .NET Framework. You only need to use the C# 9 version of the compiler. That compiler ships both with VS 2019.8 and the .NET 5 SDK. But targeting .NET 5 is not necessary.

Following your repro steps, I hit the same symptom you did. But only when my IDE/project was configured to use packages.config. If I removed the packages from the project and changed my IDE to prefer PackageReference, then reinstalled the "Microsoft.Windows.CsWin32" package, it worked.

So, I'm going to reactivate and retitle your issue to track that this doesn't work with packages.config and will investigate whether we can fix that. I also filed microsoft/win32metadata#180 to track another minor issue I saw with packages.config that must be fixed in the metadata.

Thank you for your report. In the meantime, can you switch from packages.config to PackageReference? It's a much better world anyway 😉.

@AArnott AArnott reopened this Jan 24, 2021
@AArnott AArnott changed the title Does not support .NET Framework 4.x projects Source Generator not installed for packages.config projects Jan 24, 2021
@AArnott AArnott added the bug Something isn't working label Jan 24, 2021
@riverar
Copy link
Author

riverar commented Jan 24, 2021

@AArnott Thanks Andrew. Definitely confused here because according to Microsoft elsewhere, C# 9 requires .NET 5.

C# 9.0 is supported on .NET 5. For more information, see C# language versioning.
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9

@AArnott
Copy link
Member

AArnott commented Jan 24, 2021

You're making the understandable mistake of confusing compiler versions with language versions. Using the C# 9 language version is only officially supported on the .NET 5 runtime, it is true. However this source generator only requires the C# 9 version of the compiler. Your project can still set C# 7.3 or 8 as its LangVersion and the source generator will still run, and you'd still be on a supported path.

That said, the source generator may generate syntax that only the C# 9 language version will parse. For example, we do generate function pointers at times, and that requires the C# 9 language version. But you may not even need to generate any function pointers, and you'd be fine with a lesser language version.
Or you could even go ahead and use C# 9 language version for your .NET Framework targeted projects (as I do for many of my projects). In my experience it still works great -- just avoid the features listed as requiring a newer runtime than you are targeting.

@riverar
Copy link
Author

riverar commented Jan 24, 2021

csc /? produces:

Microsoft (R) Visual C# Compiler version 3.9.0-1.20521.14 (182c1e33)
Copyright (C) Microsoft Corporation. All rights reserved.

The README states:

Source Generators require C# 9, which comes with the .NET 5 SDK or Visual Studio 2019 Update 8 (16.8).

Note no mention of language or compiler. And if it was amended to say C# 9 compiler, how would users know if they have this compiler given the above print out?

Don't get me wrong, am happy to be wrong in this case. But perhaps a takeaway here is that a WinDev MVP was confused, so this may not be the best onboarding experience. 😆

@Micke3rd
Copy link

Micke3rd commented Jan 24, 2021

You're making the understandable mistake of confusing compiler versions with language versions

He doesn't. C# 9 is the name and version of a language, not a compatible compiler.

@AArnott
Copy link
Member

AArnott commented Jan 24, 2021

@Micke3rd Fair enough. I'll revise my wording going forward and update the published docs on this repo to be more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants