AArnott / CodeGeneration.Roslyn

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

Cannot install dotnet-codegen #196

Closed Nihlus closed 4 years ago

Nihlus commented 4 years ago

When trying to create a new minimal project with 0.7.5-alpha, the installation of dotnet-codegen fails with a NU1212 error. The reason for this is, as far as I can tell, that the package type is explicitly specified in https://github.com/AArnott/CodeGeneration.Roslyn/blob/master/src/CodeGeneration.Roslyn.Tool/CodeGeneration.Roslyn.Tool.csproj#L4 as DotnetCliTool, whereas the most recent version of dotnet expects DotnetTool.

A possible workaround or solution would be to drop the explicit package type specification, and use <PackAsTool>true</PackAsTool> instead (as seen in https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools-how-to-create).

jarl@nessie ~ $ dotnet --version
3.1.102
jarl@nessie ~ $ dotnet --list-sdks
2.1.804 [/usr/share/dotnet/sdk]
3.1.102 [/usr/share/dotnet/sdk]
jarl@nessie ~ $ dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
amis92 commented 4 years ago

@Nihlus and what did you attempt as a command for installing dotnet-codegen?

Unfortunately, there's no command-line command to do that, you have to manually edit the project file.

Also, while you're at it, 0.7-alpha is unusable as seen in #195

Nihlus commented 4 years ago

@amis92 No command at first, just letting dotnet restore figure things out. After that failed, I ended up trying to install it as a global tool, which didn't work for the same but more verbose reason.

Strangely, it all started working for no apparent reason a little earlier today. I tried adding the tool with dotnet add package first, and then changing it to a tool reference - apparently that jogged something, and the generators are working fine now.

Nihlus commented 4 years ago

I've attempted to recreate the issue on another computer, and there I can't get things to work at all. It still functions on my laptop, which is extremely bizarre.

EDIT: After some investigation, I found that I somehow had managed to install dotnet-codegen as a tool in my local nuget cache, and that was how it was working. I still have no idea how that happened. As far as I can tell, as long as the tool is updated to conform to the new SDK tool standards (with the package type and naming), it should work fine out of the box.

amis92 commented 4 years ago

This will be fixed via #198.