-
Notifications
You must be signed in to change notification settings - Fork 416
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
Allow defining script target framework via configuration #1154
Allow defining script target framework via configuration #1154
Conversation
related issue: dotnet-script/dotnet-script#246 |
The It is not used during script execution since we only support scripts that targets It is not actually up to the script to determine if the target framework should be So how do we indicate that the script should be treated as a .Net Core script? My suggestion is that we make this option define the target runtime rather than the target runtime. {
"script": {
"defaultTargetRuntime": ".NetCore"
}
} If no shebang is defined in the script, this is the runtime we use. If not defined as an option, it defaults to Imagine the following script
This also means that on *nix, we can execute the script like this.
That would not of course work on Windows, but the shebang can still be used by OmniSharp to determine the target runtime. From OmniSharp we could make a convention that if the sheban contains "dotnet script" or "dotnet-script", we set the runtime If the runtime is If the shebang is missing we resolve to the setting if specified. If neither, we fall back to "NET46".
Just my two cents 😀 |
Let's stick to only controlling this over TFM. This is the runner agnostic approach that we'd like to have in OmniSharp. In general I like the idea of inferring the script runtime based on {...something...} if possible, but that is something better suited for a plugin into OmniSharp, I'd not put that into the core functionality. |
Also updated the changelog - should be good to go 👍 |
I agree. LGTM |
At the moment, in the script project system, the following model is used:
net46
, without Nuget support in scripts - to support typical usage withcsi.exe
for Desktop .NETEnableScriptNuGetReferences = true
in the OmniSharp settings, then OmniSharp additionally can resolve inline script NuGet packages (also innet46
context)!# "netcoreapp2.0"
then OmniSharp used .NET Core context instead of Desktop .NET to resolve the packages - the typical usage scenario are folks running scripts with dotnet-script for .NET CoreSince
!# "{framework}"
has no runtime meaning for the script runner - it's only used for OmniSharp to know how to resolve the compilation dependencies - this PR allows implicitly setting the framework version via the configuration file, instead of just reading it via the!# "{framework}"
.For example, I could have an
omnisharp.json
file:This means that I can now author all my scripts without
!# "netcoreapp2.0"
. This is beneficial for users who do not care aboutcsi.exe
and want to always use Nuget package resolution in scripts + .NET Core only for scripting.Additionally, the way the code is set up, setting .NET Core as
defaultTargetFramework
would automatically opt into nuget package references since the two must go together.As a bonus I added a strongly typed config object for script project system.