AArnott / CodeGeneration.Roslyn

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

Doesn't work with Microsoft.NET.SDK based project #54

Closed smaillet closed 5 years ago

smaillet commented 6 years ago

Repro steps

1) Load TestRoslynGenerator solution TestRoslynGenerator.zip into VS2017 1) I've tried with 15.4.1 and 15.5.0 Preview 2 same results 2) Build the solution (F6)

Expected

successful build

Actual

Error MSB6006 "dotnet" exited with code 1

Additional Details

After enabling full diagnostics in MSBuild I found the call to dotnet.exe and a message that provides some further hint on the problem:

dotnet codegen 
-r C:\Users\USERNAMEXYZ\.nuget\packages\codegeneration.roslyn.attributes\0.4.11\lib\netstandard1.0\CodeGeneration.Roslyn.Attributes.dll 
-r C:\Users\USERNAMEXYZ\.nuget\packages\codegeneration.roslyn\0.4.11\lib\netstandard1.5\CodeGeneration.Roslyn.dll
[ Standard .NET lib references not shown for brevity]
-r "C:\Users\USERNAMEXYZ\Documents\Visual Studio 2017\Projects\TestRoslynGenerator\TestRoslynGenerator\bin\Debug\netstandard1.5\TestRoslynGenerator.dll" 
-r C:\Users\USERNAMEXYZ\.nuget\packages\validation\2.4.13\lib\netstandard1.3\Validation.dll 
--out obj\Debug\netstandard1.5\ 
--generatedFilesList obj\Debug\netstandard1.5\y1sshcfo.ivy 
-- Consumer.cs

No executable found matching command "dotnet-codegen"

I don't pretend to understand the dotnet.exe tooling well enough to know what that means.

Suggestion

Provide complete standalone sample solution(s) that are built and validated as part of CI builds so it is easier for users to try and can catch issues in the builds

StephenStrickland commented 6 years ago

Currently blocked by this.

amis92 commented 6 years ago

@smaillet @StephenStrickland there are two changes you need to add:

in the folder with solution file you need to add nuget.config with contents as follows (specifically important is the NuGet feed for CoreFx experimental repo):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
  </packageSources>
</configuration>

and in your Consumer.csproj you need to have also this reference:

<DotNetCliToolReference Include="dotnet-codegen" Version="0.4.11" />

You can reference this (my) project for a working example using NuGet packages: https://github.com/amis92/CodeGenerationBugDemo (it's a BugDemo but it works as is, to repro the bug follow README).

amis92 commented 5 years ago

Let's call it resolved via https://github.com/jaredthirsk/CodeGeneration.Roslyn.Walkthrough - the actual sample is to be included in this repo will be tracked in #41