Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fschwiet opened this issue Jan 23, 2024 · 1 comment
Open

Comments

@fschwiet
Copy link

fschwiet commented Jan 23, 2024

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants