Closed jaredthirsk closed 7 years ago
I looked under the section for "Packaging up your code generator for others' use", which doesn't apply to me since I'm not at the point yet of packaging my code for others, and I found a hint, which is to add <DotNetCliToolReference Include="dotnet-codegen" Version="0.4.6" />
. I tried that and saw an error that System.CommandLine was missing. How do I get this installed? (I believe my nuget has the corefxlab nuget setup properly.)
UPDATE: Fix was to update the version to match the latest Nuget package I used: <DotNetCliToolReference Include="dotnet-codegen" Version="0.4.11" />
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 2017-07-29 7:52:26 AM.
Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" (1) is building "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NET462\Walkthrough.Generators.NET462.csproj" (2) on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore. [C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NET462\Walkthrough.Generators.NET462.csproj]
Done Building Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NET462\Walkthrough.Generators.NET462.csproj" (default targets) -- FAILED.
Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" (1) is building "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NETStandard15\Walkthrough.Generators.NETStandard15.csproj" (3) on node 1 (default targets).
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreGenerateAssemblyInfo:
Skipping target "CoreGenerateAssemblyInfo" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
GenerateBuildDependencyFile:
Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
Walkthrough.Generators.NETStandard15 -> C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NETStandard15\bin\Debug\netstandard1.5\Walkthrough.Generators.NETStandard15.dll
Done Building Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NETStandard15\Walkthrough.Generators.NETStandard15.csproj" (default targets).
Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" (1) is building "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Foo.NETStandard15\Walkthrough.Foo.NETStandard15.csproj" (4) on node 1 (default targets).
GenerateCodeFromAttributes:
dotnet codegen -r C:\Users\ja\.nuget\packages\codegeneration.roslyn.attributes\0.4.11\lib\netstandard1.0\CodeGeneration.Roslyn.Attributes.dll -r C:\Users\ja\.nuget\packages\codegeneration.roslyn\0.4.11\lib\netstandard1.5\CodeGeneration.Roslyn.dll -r C:\Users\ja\.nuget\packages\microsoft.codeanalysis.csharp\2.2.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll -r C:\Users\ja\.nuget\packages\microsoft.codeanalysis.common\2.2.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll -r C:\Users\ja\.nuget\packages\microsoft.win32.primitives\4.3.0\ref\netstandard1.3\Microsoft.Win32.Primitives.dll -r C:\Users\ja\.nuget\packages\system.appcontext\4.3.0\ref\netstandard1.3\System.AppContext.dll -r C:\Users\ja\.nuget\packages\system.collections.concurrent\4.3.0\ref\netstandard1.3\System.Collections.Concurrent.dll -r C:\Users\ja\.nuget\packages\system.collections\4.3.0\ref\netstandard1.3\System.Collections.dll -r C:\Users\ja\.nuget\packages\system.collections.immutable\1.3.1\lib\netstandard1.0\System.Collections.Immutable.dll -r C:\Users\ja\.nuget\packages\system.commandline\0.1.0-e170729-1\lib\netstandard1.5\System.CommandLine.dll -r C:\Users\ja\.nuget\packages\system.console\4.3.0\ref\netstandard1.3\System.Console.dll -r C:\Users\ja\.nuget\packages\system.diagnostics.debug\4.3.0\ref\netstandard1.3\System.Diagnostics.Debug.dll -r C:\Users\ja\.nuget\packages\system.diagnostics.tools\4.3.0\ref\netstandard1.0\System.Diagnostics.Tools.dll -r C:\Users\ja\.nuget\packages\system.diagnostics.tracing\4.3.0\ref\netstandard1.5\System.Diagnostics.Tracing.dll -r C:\Users\ja\.nuget\packages\system.dynamic.runtime\4.3.0\ref\netstandard1.3\System.Dynamic.Runtime.dll -r C:\Users\ja\.nuget\packages\system.globalization.calendars\4.3.0\ref\netstandard1.3\System.Globalization.Calendars.dll -r C:\Users\ja\.nuget\packages\system.globalization\4.3.0\ref\netstandard1.3\System.Globalization.dll -r C:\Users\ja\.nuget\packages\system.io.compression\4.3.0\ref\netstandard1.3\System.IO.Compression.dll -r C:\Users\ja\.nuget\packages\system.io.compression.zipfile\4.3.0\ref\netstandard1.3\System.IO.Compression.ZipFile.dll -r C:\Users\ja\.nuget\packages\system.io\4.3.0\ref\netstandard1.5\System.IO.dll -r C:\Users\ja\.nuget\packages\system.io.filesystem\4.3.0\ref\netstandard1.3\System.IO.FileSystem.dll -r C:\Users\ja\.nuget\packages\system.io.filesystem.primitives\4.3.0\ref\netstandard1.3\System.IO.FileSystem.Primitives.dll -r C:\Users\ja\.nuget\packages\system.linq\4.3.0\ref\netstandard1.0\System.Linq.dll -r C:\Users\ja\.nuget\packages\system.linq.expressions\4.3.0\ref\netstandard1.3\System.Linq.Expressions.dll -r C:\Users\ja\.nuget\packages\system.net.http\4.3.0\ref\netstandard1.3\System.Net.Http.dll -r C:\Users\ja\.nuget\packages\system.net.primitives\4.3.0\ref\netstandard1.3\System.Net.Primitives.dll -r C:\Users\ja\.nuget\packages\system.net.sockets\4.3.0\ref\netstandard1.3\System.Net.Sockets.dll -r C:\Users\ja\.nuget\packages\system.objectmodel\4.3.0\ref\netstandard1.3\System.ObjectModel.dll -r C:\Users\ja\.nuget\packages\system.reflection\4.3.0\ref\netstandard1.5\System.Reflection.dll -r C:\Users\ja\.nuget\packages\system.reflection.extensions\4.3.0\ref\netstandard1.0\System.Reflection.Extensions.dll -r C:\Users\ja\.nuget\packages\system.reflection.metadata\1.4.2\lib\netstandard1.1\System.Reflection.Metadata.dll -r C:\Users\ja\.nuget\packages\system.reflection.primitives\4.3.0\ref\netstandard1.0\System.Reflection.Primitives.dll -r C:\Users\ja\.nuget\packages\system.resources.resourcemanager\4.3.0\ref\netstandard1.0\System.Resources.ResourceManager.dll -r C:\Users\ja\.nuget\packages\system.runtime\4.3.0\ref\netstandard1.5\System.Runtime.dll -r C:\Users\ja\.nuget\packages\system.runtime.extensions\4.3.0\ref\netstandard1.5\System.Runtime.Extensions.dll -r C:\Users\ja\.nuget\packages\system.runtime.handles\4.3.0\ref\netstandard1.3\System.Runtime.Handles.dll -r C:\Users\ja\.nuget\packages\system.runtime.interopservices\4.3.0\ref\netstandard1.5\System.Runtime.InteropServices.dll -r C:\Users\ja\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll -r C:\Users\ja\.nuget\packages\system.runtime.loader\4.3.0\ref\netstandard1.5\System.Runtime.Loader.dll -r C:\Users\ja\.nuget\packages\system.runtime.numerics\4.3.0\ref\netstandard1.1\System.Runtime.Numerics.dll -r C:\Users\ja\.nuget\packages\system.security.cryptography.algorithms\4.3.0\ref\netstandard1.4\System.Security.Cryptography.Algorithms.dll -r C:\Users\ja\.nuget\packages\system.security.cryptography.encoding\4.3.0\ref\netstandard1.3\System.Security.Cryptography.Encoding.dll -r C:\Users\ja\.nuget\packages\system.security.cryptography.primitives\4.3.0\ref\netstandard1.3\System.Security.Cryptography.Primitives.dll -r C:\Users\ja\.nuget\packages\system.security.cryptography.x509certificates\4.3.0\ref\netstandard1.4\System.Security.Cryptography.X509Certificates.dll -r C:\Users\ja\.nuget\packages\system.text.encoding\4.3.0\ref\netstandard1.3\System.Text.Encoding.dll -r C:\Users\ja\.nuget\packages\system.text.encoding.extensions\4.3.0\ref\netstandard1.3\System.Text.Encoding.Extensions.dll -r C:\Users\ja\.nuget\packages\system.text.regularexpressions\4.3.0\ref\netstandard1.3\System.Text.RegularExpressions.dll -r C:\Users\ja\.nuget\packages\system.threading\4.3.0\ref\netstandard1.3\System.Threading.dll -r C:\Users\ja\.nuget\packages\system.threading.tasks\4.3.0\ref\netstandard1.3\System.Threading.Tasks.dll -r C:\Users\ja\.nuget\packages\system.threading.tasks.parallel\4.3.0\ref\netstandard1.1\System.Threading.Tasks.Parallel.dll -r C:\Users\ja\.nuget\packages\system.threading.timer\4.3.0\ref\netstandard1.2\System.Threading.Timer.dll -r C:\Users\ja\.nuget\packages\system.valuetuple\4.3.0\lib\netstandard1.0\System.ValueTuple.dll -r C:\Users\ja\.nuget\packages\system.xml.readerwriter\4.3.0\ref\netstandard1.3\System.Xml.ReaderWriter.dll -r C:\Users\ja\.nuget\packages\system.xml.xdocument\4.3.0\ref\netstandard1.3\System.Xml.XDocument.dll -r C:\Users\ja\.nuget\packages\validation\2.4.13\lib\netstandard1.3\Validation.dll -r C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NETStandard15\bin\Debug\netstandard1.5\Walkthrough.Generators.NETStandard15.dll --out obj\Debug\netstandard1.5\ --generatedFilesList obj\Debug\netstandard1.5\tpmeshx0.fk0 -- Foo.cs
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.CommandLine, Version=0.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at CodeGeneration.Roslyn.Generate.Program.Main(String[] args)
C:\Users\ja\.nuget\packages\codegeneration.roslyn.buildtime\0.4.11\build\CodeGeneration.Roslyn.BuildTime.targets(20,5): error MSB6006: "dotnet" exited with code -532462766. [C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Foo.NETStandard15\Walkthrough.Foo.NETStandard15.csproj]
GenerateBuildDependencyFile:
Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
Done Building Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Foo.NETStandard15\Walkthrough.Foo.NETStandard15.csproj" (default targets) -- FAILED.
Done Building Project "C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" (default targets) -- FAILED.
Build FAILED.
"C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" (default target) (1) ->
"C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NET462\Walkthrough.Generators.NET462.csproj" (default target) (2) ->
(ResolveNuGetPackageAssets target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore. [C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.NET462\Walkthrough.Generators.NET462.csproj]
"C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Generators.sln" (default target) (1) ->
"C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Foo.NETStandard15\Walkthrough.Foo.NETStandard15.csproj" (default target) (4) ->
(GenerateCodeFromAttributes target) ->
C:\Users\ja\.nuget\packages\codegeneration.roslyn.buildtime\0.4.11\build\CodeGeneration.Roslyn.BuildTime.targets(20,5): error MSB6006: "dotnet" exited with code -532462766. [C:\forks\CodeGeneration.Roslyn.Walkthrough\src\Walkthrough.Foo.NETStandard15\Walkthrough.Foo.NETStandard15.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:14.55
So, I got it working! At least via a project reference as you can see in my repo. I still get compile warnings: 'System.Net.Http' could not be found, in the net462 projects.
It looks like you figured it out. I've fixed the README for the comments you mentioned. If I'm missing anything else, please open a new issue or send a PR.
I made a repo for this repro: https://github.com/jaredthirsk/CodeGeneration.Roslyn.Walkthrough
Minor issues with the walkthrough instructions:
"This must be done in a library that targets netstandard1.3 or net46 (or later)": I created a new NETStandard 1.3 project and added CodeGeneration.Roslyn but it says "Package CodeGeneration.Roslyn 0.4.11 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package CodeGeneration.Roslyn 0.4.11 supports: netstandard1.5 (.NETStandard,Version=v1.5) One or more packages are incompatible with .NETStandard,Version=v1.3."
"You may need to define this property in your .NET SDK netstandard project to workaround the problem with the Microsoft.Composition NuGet package:" Why would I need to follow this instruction? What is the symptom that would show me I need to do this? (What does the Microsoft.Composition package have to do with anything?)
Breaking problem:
I created a .NETStandard 1.5 library that references my NETStandard 1.5 generator library but I get this build output:
It's hiding the actual error. If I run msbuild from the developer command prompt, here is the output: (I tried using bold to highlight errors but it doesn't work inside a code block. So search for ** to see interesting parts.)