Closed louthy closed 4 years ago
Quick answer: try to look at demo from README https://github.com/AArnott/CodeGeneration.Roslyn#how-to-write-your-own-code-generator
Longer answer:
You'll probably need to add CodeGeneration.Roslyn.Plugin.Sdk
Sdk reference in your generator project; but that depends very much on how you distribute your packages. For the default case referencing that Sdk should do it.
I have been going around in circles trying to make this work. I spent 4 hours last week trying to make it work, had to pause it, and have come back to it again to try, even with the basic settings, to get something moving and it's going nowhere.
After trying to get the complex multi-target nu-get version working (which I don't see how it could ever work when there's only one props in the package pointing to one target and dotnet pack
complains about multiple targets); I went back to trying to get at least something working.
Today:
Code-generator project file:
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Build">
<PropertyGroup>
<RoslynCodeGenVersion>0.7.5-alpha</RoslynCodeGenVersion>
</PropertyGroup>
<Sdk Name="CodeGeneration.Roslyn.Plugin.Sdk" Version="0.7.5-alpha" />
<PropertyGroup>
<PackageVersion>3.4.5</PackageVersion>
<PackageId>LanguageExt.CodeGen</PackageId>
<Title>LanguageExt.CodeGen</Title>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CodeGeneration.Roslyn" Version="$(RoslynCodeGenVersion)" />
</ItemGroup>
</Project>
The attributes project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.0;net461</TargetFrameworks>
<PackageVersion>3.4.5</PackageVersion>
<PackageId>LanguageExt.CodeGen.Attributes</PackageId>
<OutputType>library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CodeGeneration.Roslyn.Attributes" Version="[0.7.5-alpha, )" />
</ItemGroup>
</Project>
After dotnet pack I create an empty netcoreapp2.1
console-app:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LanguageExt.CodeGen"
Version="3.4.5"
PrivateAssets="all" />
<PackageReference Include="LanguageExt.CodeGen.Attributes"
Version="3.4.5"
PrivateAssets="all" />
<PackageReference Include="CodeGeneration.Roslyn.BuildTime"
Version="0.7.5-alpha"
PrivateAssets="all" />
<DotNetCliToolReference Include="dotnet-codegen"
Version="0.7.5-alpha" />
</ItemGroup>
</Project>
And get:
1>ConsoleApp35.csproj : error NU1202: Package LanguageExt.CodeGen 3.4.5 is not compatible with netcoreapp2.1 (.NETCoreApp,Version=v2.1). Package LanguageExt.CodeGen 3.4.5 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
1>ConsoleApp35.csproj : error NU1212: Invalid project-package combination for LanguageExt.CodeGen 3.4.5. DotnetToolReference project style can only contain references of the DotnetTool type
If I open up the package in NuGet Package Explorer, there's a props file in the build folder:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<CodeGenerationRoslynPlugin Include="$(MSBuildThisFileDirectory)../tools/netcoreapp2.1/any/LanguageExt.CodeGen.dll" />
</ItemGroup>
</Project>
And a tools\netcoreapp2.1\any
folder with my CodeGen dll and all the other refs.
So, if I then change the netcoreapp2.1
to netcoreapp3.0
in the code-generator project file and update the console-app to netcoreapp3.0
too, I get:
ConsoleApp36.csproj : error NU1202: Package LanguageExt.CodeGen 3.4.5 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package LanguageExt.CodeGen 3.4.5 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
ConsoleApp36.csproj : error NU1212: Invalid project-package combination for LanguageExt.CodeGen 3.4.5. DotnetToolReference project style can only contain references of the DotnetTool type
I figure something is being cached somewhere, because the nuget file has 3.0 refs in it. So, I create a new ConsoleApp and get the same.
By the way, I am using a folder in VS -> Settings -> NuGet Package Manager -> Package Sources to find the packages without having to deploy them to nuget.org
Then, just for the hell of it, I try netstandard2.1
in the generator project file, and get:
error NETSDK1054: only supports .NET Core. [I:\dev\language-ext\LanguageExt.CodeGen\LanguageExt.CodeGen.csproj]
I also tried netstandard2.0
with the same result.
So, then I tried (in the generator project file). And increased the version number to 3.4.6
.
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
This throws out the following warning:
C:\Users\paul\.nuget\packages\codegeneration.roslyn.plugin.sdk\0.7.5-alpha\Sdk\BuildPluginPackage.targets(53,5): warning : CreatePluginPackageBuildProps target requires a single TargetFramework to be used for packing. You can override this by calling e.g. 'dotnet pack -p:TargetFrameworks=netcoreapp2.1' to pack the tool for that TFM. [I:\dev\language-ext\LanguageExt.CodeGen\LanguageExt.CodeGen.csproj]
That seems to imply that only one target can exist in a nuget package. This is very, very poor.
If I open it up in Package Explorer I see two tools folders for netcoreapp2.1
and netcoreapp3.0
, but only one props referencing netcoreapp2.1
If I set the console-app to look at the new package (with netcoreapp3.0 still set for its framework) I get:
ConsoleApp37.csproj : error NU1202: Package LanguageExt.CodeGen 3.4.6 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package LanguageExt.CodeGen 3.4.6 supports:
ConsoleApp37.csproj : error NU1202: - netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
ConsoleApp37.csproj : error NU1202: - netcoreapp3.0 (.NETCoreApp,Version=v3.0) / any
ConsoleApp37.csproj : error NU1212: Invalid project-package combination for LanguageExt.CodeGen 3.4.6. DotnetToolReference project style can only contain references of the DotnetTool type
So, it's complaining that netcoreapp3.0
is not compatible with netcoreapp3.0
. Nice.
If I change the console-app back to netcoreapp2.1
I get:
ConsoleApp37.csproj : error NU1202: Package LanguageExt.CodeGen 3.4.6 is not compatible with netcoreapp2.1 (.NETCoreApp,Version=v2.1). Package LanguageExt.CodeGen 3.4.6 supports:
ConsoleApp37.csproj : error NU1202: - netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
ConsoleApp37.csproj : error NU1202: - netcoreapp3.0 (.NETCoreApp,Version=v3.0) / any
ConsoleApp37.csproj : error NU1212: Invalid project-package combination for LanguageExt.CodeGen 3.4.6. DotnetToolReference project style can only contain references of the DotnetTool type
I am yet to get anywhere close to getting a package working. Perhaps I'm missing something, but I can't help feeling this has all got a lot more complex than it perhaps needs to be. Certainly, the inability to support multiple targets seems to be a major step backwards, although just getting one working would be nice right now. It seems a PhD in project files is needed, which may work for the authors of this project, but is pretty impenetrable for the rest of us.
@louthy your problem sounds a bit like what is presented in https://github.com/AArnott/CodeGeneration.Roslyn#multitargeting-generator
Does it solve your problem?
Also, because we are a tool, we can't really multi-target. That's why the limitation exists, and the link describes how to workaround it.
But I can’t even target one platform successfully. Is there anything in particular there that you’re referring to, because my comments above are a fraction of the attempts I’ve tried to make this work, trying all combos of settings I could.
If I could make it work for one platform I would at least have some idea of whether I was on the right track or not.
I just updated visual studio too to see if there was something going awry there, but now visual studio doesn’t recognise my c# projects (!!!), so right now I’m pretty frustrated and will probably have to roll back to the last version and will wait for others to have successes or look for alternative code-gen solutions.
One thing to note from the documentation: there are often references to project files without being explicit as to whether it’s the generator project, consuming project, or attributes project, so assumptions are made in an attempt to decipher. Some clarity in the language could help, maybe.
Well for what it's worth, I'm investigating what's going on. From the looks of it, it may be the case that my design for the Plugins is flawed and cannot work.
Please bear with me, but since it's shaping up as a core design flaw, it'll probably take time to resolve. As in, days or weeks. :(
Sure, thanks for letting me know. I have attached my nupkg
files in case it helps you at all.
This specific issue will be resolved via #198.
I see the 'NuGet generator publisher' section of the migrations page isn't complete yet. I am seeing problems consuming the nuget package.
The issues are the same as previously reporting with the Project-to-Project solution. Any chance of getting that bit of documentation completed?