Skip to content

Commit 96601ac

Browse files
committed
support for desktop .net
1 parent ccd2b51 commit 96601ac

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Dotnet.Script.Core/ScriptCompiler.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public virtual ScriptOptions CreateScriptOptions(ScriptContext context, IList<Ru
7676
.WithEmitDebugInformation(true)
7777
.WithFileEncoding(context.Code.Encoding);
7878

79+
// if the framework is not Core CLR, add GAC references
80+
if (!ScriptEnvironment.Default.IsNetCore)
81+
{
82+
opts = opts.AddReferences(
83+
"System",
84+
"System.Core",
85+
"System.Data",
86+
"System.Data.DataSetExtensions",
87+
"System.Xml",
88+
"System.Xml.Linq",
89+
"System.Net.Http",
90+
"Microsoft.CSharp");
91+
}
92+
7993
if (!string.IsNullOrWhiteSpace(context.FilePath))
8094
{
8195
opts = opts.WithFilePath(context.FilePath);

src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class ScriptEnvironment
2222

2323
private readonly Lazy<string> _nuGetStoreFolder;
2424

25+
private string _overrriddenTargetFramework;
26+
2527
private ScriptEnvironment()
2628
{
2729
_targetFramework = new Lazy<string>(GetNetCoreAppVersion);
@@ -38,14 +40,26 @@ private ScriptEnvironment()
3840

3941
public string RuntimeIdentifier => _runtimeIdentifier.Value;
4042

41-
public string TargetFramework => _targetFramework.Value;
43+
public string TargetFramework => _overrriddenTargetFramework ?? _targetFramework.Value;
4244

4345
public string InstallLocation => _installLocation.Value;
4446

4547
public string ProccessorArchitecture => RuntimeEnvironment.RuntimeArchitecture;
4648

4749
public string NuGetStoreFolder => _nuGetStoreFolder.Value;
4850

51+
public bool IsNetCore => TargetFramework.StartsWith("netcoreapp", StringComparison.InvariantCultureIgnoreCase);
52+
53+
public void OverrideTargetFramework(string targetFramework)
54+
{
55+
if (_targetFramework.IsValueCreated)
56+
{
57+
throw new InvalidOperationException($"Cannot override target framework because a value {_targetFramework.Value} has already been resolved and used.");
58+
}
59+
60+
_overrriddenTargetFramework = targetFramework;
61+
}
62+
4963
private static string GetPlatformIdentifier()
5064
{
5165
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Darwin) return "osx";

0 commit comments

Comments
 (0)