AArnott / CodeGeneration.Roslyn

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

Tutorial does not work if you change netcoreapp2.1 to netcoreapp3.1 #197

Closed AlbertoMonteiro closed 4 years ago

AlbertoMonteiro commented 4 years ago

I've followed the tutorial on readme, then I changed the netcoreapp2.1 to netcoreapp3.1, the app ran, but the class TestPassed were not generated.

My Program.cs

string runtime = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
System.Console.WriteLine(runtime);
foreach (var type in typeof(Program).Assembly.GetTypes())
    Console.WriteLine(type.FullName);

First run with <TargetFramework>netcoreapp3.1</TargetFramework> Second run with <TargetFramework>netcoreapp2.1</TargetFramework> image

If I change to netcoreapp3.0 the app does not even build

image Output

C:\Users\alberto_albuquerque\.nuget\packages\codegeneration.roslyn.buildtime\0.7.5-alpha\build\
CodeGeneration.Roslyn.BuildTime.targets(107,5): error MSB3073: 
O comando "dotnet codegen "@obj\Debug\netcoreapp3.0\Reflector.csproj.dotnet-codegen.rsp"" 
foi encerrado com o código 3. [C:\dev\codegentest\Reflector\Reflector.csproj]       

Ocorreu uma falha no build. Corrija os erros de build e execute novamente.

It is in portuguese(pt-br) but it says that the command dotnet codegen exited with code 3

AlbertoMonteiro commented 4 years ago

I've changed the way to get the TF being used

using System;
using System.Reflection;
using System.Runtime.Versioning;

namespace Reflector
{
    class Program
    {
        static void Main(string[] args)
        {
            var framework = Assembly
                .GetEntryAssembly()
                ?.GetCustomAttribute<TargetFrameworkAttribute>()?
                .FrameworkName;

            System.Console.WriteLine(framework);
            foreach (var type in typeof(Program).Assembly.GetTypes())
                Console.WriteLine(type.FullName);
        }
    }
}

image

AlbertoMonteiro commented 4 years ago

I've noticed that the filed was generated in 3.1, but with no class content, as you can see in the image below image

amis92 commented 4 years ago

I cannot reproduce using v0.7.43-alpha. Closing as deprecated.

In case you still experience problems @AlbertoMonteiro please reopen and provide a zip with the exact files you use.