Closed trampster closed 3 years ago
Try changing the Initialize method argument to GeneratorInitializationContext
instead of InitializationContext
.
error CS0246: The type or namespace name 'GeneratorInitializationContext' could not be found (are you missing a using directive or an assembly reference?)
ISourceGenerator requires the old names, unless I also need to update my nuget references:
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0-3.20207.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0-beta2.final" PrivateAssets="all" />
see #47681
add the following key to your NuGet.config:
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
and update Microsoft.CodeAnalysis.CSharp to 3.8.0-4.20464.1.
I don't have a package reference to Microsoft.CodeAnalysis.CSharp at all, or do you mean Microsoft.CodeAnalysis.CSharp.Workspaces?
I updated my NuGet.config found in ~/.config/NuGet
And added a PackageReference
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-4.20464.1" PrivateAssets="all" />
But that just resulted in this error
/home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/JsonSrcGen.Generator.csproj : error NU1102: Unable to find package Microsoft.CodeAnalysis.CSharp with version (>= 3.8.0-4.20464.1) [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj] /home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/JsonSrcGen.Generator.csproj : error NU1102: - Found 214 version(s) in https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json [ Nearest version: 3.7.0-3.20271.4 ] [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj] /home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/JsonSrcGen.Generator.csproj : error NU1102: - Found 97 version(s) in nuget.org [ Nearest version: 3.8.0-2.final ] [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj]
You must add the package source for the dotnet-tools preview packages.
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
you can either do this in VS globally or by project or solution scope.
nuget.config reference
I don't have a package reference to Microsoft.CodeAnalysis.CSharp at all, or do you mean Microsoft.CodeAnalysis.CSharp.Workspaces?
Both will work, Microsoft.CodeAnalysis.CSharp.Workspaces depends on Microsoft.CodeAnalysis.CSharp. Means updating Microsoft.CodeAnalysis.CSharp.Workspaces should do the trick as well.
OK I have it working,
My generator .csproj has the following line:
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
Which had to be changed to:
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
Note the difference is dotnett5 -> dotnet-tools
Here is my working project for for anyone else who runs into this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<PropertyGroup>
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-4.20464.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\JsonSrcGen\StringBuilderExtension.cs" Link="StringBuilderExtension.cs" />
</ItemGroup>
</Project>
See this commit for the full fix: https://github.com/trampster/JsonSrcGen/commit/b9bffdabb71c61c33246cca19a2c6fe9992579b1
I do have a question though, will this PackageSource be required in the .NET 5 full release or is just a work around to a temporary problem?
@chsienki Do we have public packages now with the changed APIs that people can reference?
We're just waiting on the 16.8p3 packages to be released. We're in a slightly odd situation where a few things are out of sync :/
Version 3.8.0-3.final is now available on the public feeds https://www.nuget.org/packages/Microsoft.CodeAnalysis/3.8.0-3.final
Closing this, as it should be resolved with the public packages. Please let us know if you're not seeing the expected resolution.
The public packages have some warnings
1>C:\Users\Glenn\source\repos\ReactiveMarbles.ObservableEvents\ReactiveMarbles.ObservableEvents.SourceGenerator\ReactiveMarbles.ObservableEvents.SourceGenerator.csproj : warning NU1603: Microsoft.CodeAnalysis.Common 3.8.0-3.final depends on System.Collections.Immutable (>= 5.0.0-preview.8.20371.14) but System.Collections.Immutable 5.0.0-preview.8.20371.14 was not found. An approximate best match of System.Collections.Immutable 5.0.0-preview.8.20407.11 was resolved.
1>C:\Users\Glenn\source\repos\ReactiveMarbles.ObservableEvents\ReactiveMarbles.ObservableEvents.SourceGenerator\ReactiveMarbles.ObservableEvents.SourceGenerator.csproj : warning NU1603: Microsoft.CodeAnalysis.Common 3.8.0-3.final depends on System.Reflection.Metadata (>= 5.0.0-preview.8.20371.14) but System.Reflection.Metadata 5.0.0-preview.8.20371.14 was not found. An approximate best match of System.Reflection.Metadata 5.0.0-preview.8.20407.11 was resolved.
Seems they are relying on unreleased nuget packages.
Can open an issue if it makes sense to do so.
@333fred The issue above is fixed by your further upgrading of packages, I'd hope?
Yes, that will be fixed in RC2/16.8p4. The change didn't quite make RC1/16.8p3
Version Used: 5.0.100-rc.1.20452.10
Steps to Reproduce:
Expected Behavior: Generates source code for json
Actual Behavior:
The Method 'Initialize' exists, and it hasn't changed since the code was working with the Previews.