Skip to content

Simplify .NET SDK version handling logic - #764

Merged
Andy Gerlicher (AndyGerlicher) merged 1 commit into
microsoft:mainfrom
kasperk81:patch-1
Nov 16, 2026
Merged

Andy Gerlicher (AndyGerlicher) merged 1 commit into
microsoft:mainfrom
kasperk81:patch-1

Conversation

@kasperk81

Copy link
Copy Markdown
Contributor

Andy Ayers (@AndyAyersMS) it will scale better and enable net12 preview release which dotnet repos are currently using.

@AndyGerlicher
Andy Gerlicher (AndyGerlicher) merged commit b31b274 into microsoft:main Nov 16, 2026
3 checks passed
@jeffkl

Copy link
Copy Markdown
Collaborator

Andy Gerlicher (@AndyGerlicher) this simplification will work at run time, but not if there is no assets. The SlnGen tool is a shim that runs the correct EXE for the configured version of .NET based on global.json. So if .NET 12 is selected, it will try to run the net12.0 slngen. But if the package doesn't contain it, then it will fail in a strange way, which is why the code was written to just log an error that SlnGen doesn't currently support that .NET. So I think there should still be logic in SlnGen that detects what versions it supports.

Andy Gerlicher (AndyGerlicher) added a commit that referenced this pull request Nov 16, 2026
Move the .NET SDK to SlnGen target framework selection into a shared
SlnGenFramework helper so it can be unit tested. The tests cover SDK 10/11
selecting their matching build regardless of the runtime running the tests
(which fails with the Environment.Version approach from #764), a newer SDK
without a matching build being reported as unsupported, a newer SDK being
picked up automatically once its build is in the package, and older or
unparseable SDK versions.

Also clarify the "not supported" error: the SDK may be selected without a
global.json, so refer to the currently configured SDK and suggest pinning a
supported SDK via global.json.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5c98cb9a-2a07-496a-bfa1-68cf9e8a1498
Andy Gerlicher (AndyGerlicher) added a commit that referenced this pull request Nov 17, 2026
* Select SlnGen framework from the .NET SDK version in global.json

#764 switched framework selection to the runtime version of the tool shim
(Environment.Version). Because the shim uses RollForward=LatestMajor, this
picks the newest installed runtime rather than the SDK selected by
global.json, so a machine with a newer runtime than SlnGen ships for fails
with 'SlnGen not found' even if global.json pins a supported SDK.

Go back to using the SDK major version, but instead of a hard-coded list,
check whether the package contains a matching slngen/netX.0 build and show
the friendly 'not supported' error otherwise. Adding a new target framework
to the tool project is now all that's needed to support a new SDK.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 06156545-6fe1-415f-b5ee-31214628068c

* Extract SlnGen framework selection and add tests

Move the .NET SDK to SlnGen target framework selection into a shared
SlnGenFramework helper so it can be unit tested. The tests cover SDK 10/11
selecting their matching build regardless of the runtime running the tests
(which fails with the Environment.Version approach from #764), a newer SDK
without a matching build being reported as unsupported, a newer SDK being
picked up automatically once its build is in the package, and older or
unparseable SDK versions.

Also clarify the "not supported" error: the SDK may be selected without a
global.json, so refer to the currently configured SDK and suggest pinning a
supported SDK via global.json.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5c98cb9a-2a07-496a-bfa1-68cf9e8a1498

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 06156545-6fe1-415f-b5ee-31214628068c
Copilot-Session: 5c98cb9a-2a07-496a-bfa1-68cf9e8a1498
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

Successfully merging this pull request may close these issues.

3 participants