Developing a shared framework requires admin rights
We develop the Microsoft.AspNetCore.App shared framework in https://github.com/aspnet/AspNetCore, and it is currently difficult for our contributors to actually run tests against the shared framework. Corehost only resolves shared frameworks from $DOTNET_ROOT/shared/Microsoft.AspNetCore.App/ or the global location, which means there are basically two options for our contributors:
- Install a copy of the .NET Core SDK and runtimes in
$repoRoot/.dotnet. This is less than ideal because Visual Studio won't find the runtime becauseC:\Program Files\dotnet\dotnet.exeis typically on PATH first. - Build the shared framework locally an install in to $DOTNET_ROOT. This is also less than ideal because it pollutes the .NET Core installation with an un-released runtime, and either requires admin rights to C:\Program Files\ or requires you to configure a machine to use dotnet.exe from a user-writable location. (Again, also difficult if you don't have admin privileges).
Request
Is there way we could have corehost resolve shared frameworks from a local directory? For example, could we add a shared framework probing path in runtimeconfig.dev.json?
Ideally, I'd love for Visual Studio to pick up the local builds of our shared framework without needing administrative access to a machine, and overriding a handful of environment variables.
cc @davidfowl
There's dotnet/cli#10100 which will add the ability to install SDK (and frameworks) into a user specified location which will effectively replace the current ProgramFiles one. The location will be in registry (probably machine wide), so the first time setup requires admin rights, but after that if the location is user accessible, normal user can write there as well.
This would not solve the problem of "polluting" the global location with developer bits though.
I think that right now the best way to do this is through the DOTNET_ROOT variable. It makes it explicit in the sense that if I want to run against the developer bits, I have to set the env variable.
Alternatively you can run the dotnet.exe from the desired directory and it will look in its subtree (that's what our repos do when building using the toolchain). This probably won't help with the VS case though.
As for having a probing path in runtimeconfig.dev.json - this is a bit problematic. For a 100% correct solution the hostfxr lookup itself would need to be able to follow this, which would require dotnet.exe to parse the runtime config. That's a rather large change.
As for having a probing path in runtimeconfig.dev.json - this is a bit problematic.
Just trying to understand better... Don't we already have code which parses the app's runtimeconfig.json to know which shared framework name and version we are looking for? I would have thought adding a probing path could just be one more input to the 'find a framework' code. I was considering sending a PR for this since it's important to my team, and was looking at putting code into this method https://github.com/dotnet/core-setup/blob/master/src/corehost/cli/runtime_config.cpp#L175. I didn't actually write it yet though. Is there sometime I'm missing about the order in which json parsing and fx lookup happens?
That would work in most cases. The problem is not with the framework but with how dotnet.exe finds hostfxr.dll - this happens before any framework resolution is attempted.
Basically the problem is that if your global location only has let's say 2.2 as the latest installed, its hostfxr is also 2.2. So running the global dotnet.exe (without additional changes) would find the 2.2 hostfxr which would then parse the runtimeconfig.json and in the end try to load a 3.0 (for example) hostpolicy. While we try to keep things backward and forward compatible, it's not really a supported scenario to use lower version hostfxr in combination with higher version hostpolicy. The general design is that we always use the highest possible version of hostfxr (which can then talk to any equal or lower version of hostpolicy). But with the above change, we would not find the highest version.
I'm trying to understand why the DOTNET_ROOT env variable is not good enough. For command line tooling it should be fine. The only scenario where it is somewhat cumbersome is VS, where it would require to start VS through some script which sets the variable first and then runs VS. Are there are concerns?
I understand your concern now. I think this concern mostly applies to Microsoft.NETCore.App. Other shared frameworks shouldn't be implementing their own hostfxr or policies, so I would be okay if an option like "additionalFrameworkProbingPaths" was supported but only applied to additional frameworks, not the root framework.
The primary reason I think DOTNET_ROOT is insufficient is that it's not something we can set in a .sln file or global.json. Despite all attempts to document this clearly, first thing contributors typically do with our source code is open a Visual Studio solution file. Mayhem follows. I regularly field questions from devs struggling to get started with our code. The next thing I'm considering is a dancing bear gif in our README.md holding a sign that says "for real, you should actually read me".
An alternative worth considering is the ability to specifying DOTNET_ROOT in global.json, dotnet.json, .config/dotnet.json...some kind of config file we can check in, don't care what it looks like. I figured that would required more coordination with VS, Omnisharp, and VS4Mac teams, which is why I didn't jump that that idea at first.
cc @dsplaisted
I personally think that this is something which VS should have an option for, ideally as an MSBuild property (but then it's a chicken and egg problem I guess). The fact the VS forces the use of the same dotnet on all projects in it feels wrong.
I think that if the runtime would be to support this, then the right place would be the global.json as it already handles a similar concern for SDK. Unfortunately implementing this could be relatively ugly. I would have to look into this some more.
Update to this thread - I'm going to workaround this limitation. I would still love to see a proper fix because what I'm doing feels just plain wrong. But, I don't have other options.
I’m still running into problems getting the aspnet/AspNetCore repo to build and test the Microsoft.AspNetCore.App shared framework. The workarounds I've tried still run into this problem: using Visual Studio plus a custom shared framework is fragile.
To solve these problems, I’d like to make a pull-request to core-setup to add the option I think I need to corehost. Is this something you would accept?
Proposal
Add support to the host for listing additional folders that might contain a shared framework.
Usage
In runtimeconfig.json (or runtimeconfig.dev.json), support parsing a new option, “additionalFrameworkProbingPaths”, which an be used to list new folders that contain shared frameworks. For instance, in the aspnet/AspNetCore repo where we develop the Microsoft.AspNetCore.App shared framework, I would change the repo to generate a runtimeconfig.dev.json that looks like this:
{
"runtimeOptions": {
"additionalFrameworkProbingPaths": [
"C:\\src\\aspnet\\AspNetCore\\artifacts\\bin\\Debug\\shared\\"
]
}
}
This allows me to create a folder like "C:\src\aspnet\AspNetCore\artifacts\bin\Debug\shared\Microsoft.AspNetCore.App\9.9.9-dev\", and keep tools like dotnet test and Visual Studio working correctly.
Behavior
Folders listed in additionalFrameworkProbingPaths are treated as additional folders in the already-existing multi-level shared framework lookup code. These folders are simply additional locations to be searched for shared frameworks. The same rollforward versioning policies apply to these shared frameworks.
cc @vitek-karas @Pilchie @dagood
Also tagging @livarcocc
I think this sounds reasonable. To make the behavior predictable I would add:
- Only the application's
.runtimeconfig.jsoncan specify this value. Values specified in framework.runtimeconfig.jsonwill be ignored. - For simplicity the option would also be supported in
.runtimeconfig.dev.json. If the value is in both, the lists will be merged.
@natemcmaster I absolutely love your idea of fixing this common scenario. Every repository that deals with composing its own framework hit this. Just one ask, why not encode that in the global.json instead?
Discussed a little in chat, but posting here for posterity. The problem I want to solve is that the AspNetCore repo currently needs to write its shared framework into the installation of dotnet in order for the host to pick it up. Because of the way MSBuild does incrementalism, switching between release and debug in VS or on command line may result in tests or build not actually using up-to-date bits. Global.json doesn't work because we don't have a way to flow the VS configuration setting into the host. Runtimeconfig.dev.json seems like a better solution because build output is already config-specific.
OK the configuration specific point makes sense.
There's one other problem with global.json. Currently the host only reads this file when it invokes SDK commands. Running apps will never look at that file. Note that starting to do so would introduce several issues:
- Perf regression - not only the JSON parsing if there's one - which is probably small, but searching the disk. The
global.jsonlookup goes and walks the path to the root of the file system looking for one. So in the 99% case where there's no such file, we would still pay the price for it. This has been discussed before - one suggested potential workaround is to only do this if there's env. variable set (which would require VS changes to actually set that variable from VS). - Security - reading "random" file from disk which can affect what gets executed (in this case VERY substantially as it could point us to a custom coreclr.dll) is a potential security issue. The difference between
global.jsonandruntimeconfig.jsonis thatglobal.jsoncan be in any directory above, while theruntimeconfig.jsonis part of the app and must be in the same directory. So from a security standpoint - modifyingruntimeconfig.jsonis not that interesting as you can also modify the app itself and gain execution that way.global.jsonis different since you might not be able to modify the app, but you may be able to modify theglobal.json.
I do agree that it's not as "nice" since we can't easily do it globally for all projects in a repo. That said, we should be able to modify the build system in the repo such that it produces the right .runtimeconfig.json by default for all apps in it. Or in fact probably the .runtimeconfig.dev.json as this setting is more like the other things we write to .runtimeconfig.dev.json.
Given the argument that we want to have different shared framework folders for different configurations I'm in favor of runtimeconfig.json now.
That said, we should be able to modify the build system in the repo such that it produces the right .runtimeconfig.json by default for all apps in it.
That should easily doable with a template.runtimeconfig.json. If you think about additional support, sure.
Or in fact probably the .runtimeconfig.dev.json as this setting is more like the other things we write to .runtimeconfig.dev.json.
Agreed.
Spoke with @ericstj about this and he mentioned that the runtimeconfig.json file might not be the best place for this setting as that configuration file should be portable. The runtimeconfig.dev.json seems most appropriate here.
@vitek-karas is there support for modifying the runtimeconfig.dev.json with a template similar to what is possible with a template.runtimeconfig.json file?
@nguerrera would know about the runtimeconfig.dev.json support in the SDK.
That said, maybe in 3.0 we don't actually need the SDK to produce that file at all - in 3.0 build will include all dependencies in the app, so the probing paths which are normally written to the runtimeconfig.dev.json are not actually useful for anything. So we might be able to simply overwrite the file with our own.
Yes, we're discussing removing .dev.json from default output. You could overwrite it. There's not a template mechanism for it.
/cc @blowdart @jkotas @ericstj - we are planning to introduce this setting soon... if you have concerns please let us know.
Short version:
Adding additionalFrameworkProbingPaths property into .runtimeconfig.json and .runtimeconfig.dev.json (we would only recommend using it in the .dev file as it is machine specific). The paths specified would be added to the end of the list of paths considered when searching for frameworks - currently that list contains (by default) the location from where the dotnet.exe was executed, the globally registered location (on Windows that's in registry) and the global default location (on Windows that's program files).
Update to this thread - I'm going to workaround this limitation. I would still love to see a proper fix because what I'm doing feels just plain wrong.
@natemcmaster What is your current workaround? Is the proposed fix going to move the needle enough for you?
It does not really solve the crux of the problem that you cannot point Visual Studio to the local runtime +SDK copy.