AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 59 forks source link

Cannot get dotnet-codegen #50

Closed M-Pixel closed 6 years ago

M-Pixel commented 6 years ago

Here is a screencast of my attempt to follow the readme: http://somup.com/cbQUrbVbPx

  1. Started a new project in Visual Studio 2017
  2. Added a second project to the solution ("Your generator cannot be defined in the same project that will have code generated for it")
  3. "Install the CodeGeneration.Roslyn NuGet Package." via Visual Studio's NuGet GUI
  4. "Define the generator class:"
  5. "Define attribute" in the main project (rather than the Generator project) because "define your attribute in another assembly if it must be applied to projects that target older platforms."
  6. "install the CodeGeneration.Roslyn.Attributes package" to the main project
  7. "Define your attribute class." and "specify the assembly-qualified name of the generator type as a string instead"
  8. BUILD FAILS because dotnet-codegen doesn't exist. Skim through issues, discover that the part of the documentation about consuming a redistributed generator is actually required here.
  9. Try installing dotnet-codegen via NeGet GUI - it fails because package type 'DotnetCliTool' that is not supported by project
  10. Try installing dotnet-codegen by adding the given nuget.conf and DotNetCliToolReference XML
  11. "Make sure that the DotNetCliToolReference version matches the version of the CodeGeneration.Roslyn package your package depends on."
  12. Try command-line restore - The imported project "C:\Program Files\dotnet\sdk\1.1.0\Microsoft\Portable\v4.5\Microsoft.Portable.CSharp.targets" was not found.
  13. Try getting the dotnet-codegen by creating a new project that is dotnetcoreapp1.0, still run into DotNetCliToolReference is not supported.
AArnott commented 6 years ago

Sorry for your trouble, and thanks for your screencast. I suspect the crux of your problem is that (IIRC) code generation is currently only supported for .NET SDK style projects (since they support DotNetCliTool). So your game project that you want to generate code for isn't supported.

However, we used to support that in 0.3. So try reviewing the README in our v0.3 branch and be sure to install nuget packages from 0.3.x. I think you'll have more luck.