jburzynski / TypeGen

Single-class-per-file C# to TypeScript generator
MIT License
195 stars 55 forks source link

Typegen used old net6.0 binaries from my project instead of net8.0 #189

Open fschwiet opened 8 months ago

fschwiet commented 8 months ago

I recently upgrade a project that used net6.0 in the csproj to use net8.0. Later when I changed the C# classes that were getting typegen'd I found "dotnet typegen" didn't notice the change. It took me awhile to realize the issue as I had upgraded a bit before needing to change the C# class. To fix the issue I manually removed the net6.0 folders from my projects bin and obj directory. Then typegen started to use net8.0 binaries instead.

My tgconfig.json file is plain:

{
    "outputPath": "exports"
}

I do run typegen with a script which I'll include below. It was using typegen 2.5.0, as part of trying to figure out the problem I started to use typegen 5.0.1.

dotnet tool install --global dotnet-typegen --version 5.0.1

dotnet build

if ($LASTEXITCODE -ne 0) { throw }

$typegenOutputPath = "./web/Domain/exports"
$exportsTargetPath = "./web/client/src/app/models/imports"

if (test-path $typegenOutputPath) {
    remove-item -r -force $typegenOutputPath
}

if (test-path $exportsTargetPath) {
    remove-item -r -force $exportsTargetPath
}

dotnet typegen generate -p ./Web/Domain -v

if ($LASTEXITCODE -ne 0) { throw }

move-item $typegenOutputPath $exportsTargetPath

npx prettier --write ./web/client/src/app/models/imports

I was curious how "dotnet typegen" should actually pick the framework and build target. I saw that dotnet tools can use a global.json file (https://learn.microsoft.com/en-us/dotnet/core/versions/selection) but I did not see one of those in my solution folder.

I'm really not sure how typegen can know my intention in this case, that I wanted the net8.0 binaries to be used. So I'm not sure this is really a bug, something I should have configured, or just a limitation of the platform.

jburzynski commented 5 months ago

Currently TypeGen just searches for the first assembly that matches the project's name inside the "project output" folder (by default bin) and .NET versions are not checked, so this is currently expected. Any old assemblies need to be removed for TypeGen to find the new assembly.

I'm leaving this issue open as a potential improvement.