Chet Husk
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    In .NET 10, The .NET Runtime, MSBuild, and SDK have worked towards a [gradual loosening][decoupling-epic] of the tight coupling between the IDE (both VS and VSCode) and the CLI/SDK that the user has selected. This work is leading to much greater flexibility at the build-layer for both users and build logic authors * users can expect that when they explicitly manage SDKs, the CLI and IDE respect that explicit decision * build logic authors now have the ability to only target modern .NET and actually have that work in the VS IDE However, despite these build-time sucesses, key user experiences remain inconsistent. The _run-time_ experience of users that have customized their SDK/tool-chain selection is not consistently aware of these choices, and so cracks in our overall story around SDK management show. This document will demonstrate examples of the experiences that work and do not work today, propose a solution, and document the expected toolchain resolution behavior that all tools should adhere to in order to allow users to bring their own SDK to a much greater degree than they have in the past. ### The Happy Path Today, many .NET repos use bleeding-edge SDKs to build and test locally. They use the new [repo-local SDK] feature in .NET 10 preview 3 to inform the .NET muxer (`dotnet.exe` or `dotnet` depending on platform), via the `hostfxr` native component, that SDK resolution can be satisfied from both a repo-local directory as well as the location of the current muxer. As a result, using repo-local SDK-level tooling Just Works when using the `dotnet` CLI. Because this resolution was implemented in `hostfxr`, the .NET SDK's `MSBuildSdkResolver` component automatically inherited this new capability, and so preview builds of VS also look for and use repo-local SDKs for all SDK-resolvable Tasks/Targets when in the VS context. There are some components of the build that still come from the VS install, but there is a plan to reduce this coupling further over time. Functionally, `CTRL+B` in the IDE now uses local-SDK assets. ### Cracks in the sidewalk Unfortunately, developers do more than just build their applications. Sometimes they would like to run, debug, or test them. We'll focus on testing for now, but the scenario will also hold for many other types of interactions in the IDE. Until Microsoft Test Platform, most tests in VS and other environments are run by launching a bundled `testhost.exe` executable , which then is responsible for loading and executing the tests the user wanted to run. This `testhost.exe`component itself is a .NET Framework-dependent application. This means that it needs a .NET Runtime to execute on - and how should it find such a Runtime? It, like all other applications based on the .NET Apphost, uses our documented discovery algorithm: it tries to find a `hostfxr` and then ask it where the appropriate runtimes might be. The apphost searches for `hostfxr` in the following locations (taken from the [runtime docs][host-entry-points]): > * The app's folder is searched first. This is either the folder where the entry-point host lives or in case of apphost it is the path it has embedded in it as the app path. > * If the DOTNET_ROOT environment variable is defined, that path is searched > * The default shared locations are searched In our scenario today, this is the root (if you'll pardon the pun) of the problem - the apphosts for framework-dependent apps: * do not have a `hostfxr` alongside them * for 'global' .NET SDK installs (MSI/WinGet/pkg/Linux packages), DOTNET_ROOT is not typically set * the 'default shared locations' mentioned point to the locations of 'global' .NET SDK installs, not the user-intended repo-local install As a result, when `testhost.exe` is launched from VS, if you don't have a matching (e.g. at time of writing) 10.0.100 preview 7 runtime installed into your global install location, the dotnet/sdk repo tests simply will not launch from VS previews. The dotnet/sdk repo (and many other dotnet-org repos) have a solution for this - they typically require devs to run an environment-setup script that sets required environment variables so that VS _can_ correctly invoke apphost-based executables. This requirement is the thing we should work to solve. ## Proposal Much like the `MSBuildSdkResolver` is the centralized place for all MSBuild-based tooling to be told how to resolve/launch .NET SDK-based tooling, we need a component in each IDE we support that can supply the same kind of information to all tooling that needs to be able to correctly launch .NET framework-dependent applications. This component should ideally be based on an extraction of the logic that already exists inside the MSBuildSdkResolver today, and it should implement the [spec defined below][resolution-spec]. This component _may_ be aided by an independent packaging/distribution of `hostfxr` + managed bindings to it. There are several partial bindings that exist in various projects (SDK, MSBuild Locator, a few community ones that I'm aware of) - we should just distribute the native binary and make it easier for people to make .NET and node bindings to it, so we can reuse the logic more easily in our core editor experiences. This component _ideally_ would be able to make its changes without _requiring_ specific work from editor tooling developers. It would drastically increase the scope of work if every tool that could launch a .NET apphost in VS would need to do some work here. ## Alternative designs The above requires each tooling layer to separately include and make use of a component to do the detection and resolution. An ideal solution would only require one component to update, and deliver the feature to all .NET tools. In that spirit, it _would_ be possible for the Framework-dependent AppHosts to learn how to check the presence of global.json for _runtime_ location. If this were done, then eventually all re-built .NET applications would be able to natively do this resolution. ## SDK and Toolchain resolution specification A component that ensures uniform invocation of .NET SDK- and .NET Runtime-dependent components will * discover the location of an ambiently-available `dotnet` muxer * for `dotnet`-based tooling, this should be the path of the current process * for non-`dotnet`-based tooling (.NET Framework, node), `PATH` should be probed for the first instance of `dotnet.exe` on Windows, `dotnet` on non-Windows platforms * choose the location to search for global.json (if any) * if the tooling is solution- or project-based, then the starting directory will be the directory containing the solution or project * if the tooling is not solution- or project- based, then the currently-open workspace root (aka working directory) will be the starting directory * use a copy of `hostfxr` to resolve the SDK/tooling to use based on the chosen `dotnet` muxer path and the discovered `global.json` search root * this is effectively a call to `hostfxr_resolve_sdk2` * if the SDK is resolved successfully from this call, the values of the following environment variables should be calculated: * `DOTNET_ROOT` * should always be two directories above the resolved SDK path * e.g. `Path.GetDirectoryName(Path.GetDirectoryName(resolverResult.ResolvedSdkDirectory))` * if this value is indistinguishable from the IDE/tooling's own resolved `dotnet` muxer, this value may be omitted * components that wish to spawn .NET framework-dependent processes _must_ apply (implicitly or explicitly) the computed environment variables (if any) to their invocations before execution. ## Appendices ### A: Potential components to author as part of this * hostfxr separate distributable * needs to be separate-per-platform/RID * .NET (+ Framework) managed binding to hostfxr * Node managed binding to hostfxr * .NET (+ Framework) library to implement the resolution logic in the doc spec * Node library to implement the resolution logic in the doc spec * VS IDE component to host the .NET library (and dependencies) and provide/inject/supply the resolved vars into other tooling/VS environment/etc * VS Code IDE component to host the Node library (and dependencies) and provide/inject/supply the resolved vars into other tooling/VS Codeenvironment/etc [decoupling-epic]: https://github.com/dotnet/msbuild/issues/11142 [repo-local SDK]: https://github.com/dotnet/designs/blob/main/accepted/2025/local-sdk-global-json.md [host-entry-points]: https://github.com/dotnet/runtime/blob/43d7609b7028faac5f17bbd5de8cf9efa200121f/docs/design/features/host-components.md#entry-point-hosts [resolution-spec]: #sdk-and-toolchain-resolution-specification

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully