Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4d3914

Browse filesBrowse files
authored
Merge branch 'master' into bugfix/pdb
2 parents b73bea1 + 051c686 commit a4d3914
Copy full SHA for a4d3914

File tree

25 files changed

+355
-44
lines changed
Filter options

25 files changed

+355
-44
lines changed

‎src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public bool TryCreateHash(ExecuteScriptCommandOptions options, out string hash)
7777
{
7878
if (options.NoCache)
7979
{
80-
_logger.Debug($"The script {options.File.Path} was executed with the '--nocache' flag. Skipping cache.");
80+
_logger.Debug($"The script {options.File.Path} was executed with the '--no-cache' flag. Skipping cache.");
8181
hash = null;
8282
return false;
8383
}

‎src/Dotnet.Script.Core/Dotnet.Script.Core.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Dotnet.Script.Core.csproj
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn.</Description>
5-
<VersionPrefix>0.27.0</VersionPrefix>
5+
<VersionPrefix>0.28.0</VersionPrefix>
66
<Authors>filipw</Authors>
77
<TargetFramework>netstandard2.0</TargetFramework>
88
<AssemblyName>Dotnet.Script.Core</AssemblyName>
@@ -36,6 +36,7 @@
3636
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="2.9.0" />
3737
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
3838
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
39+
<PackageReference Include="ReadLine" Version="2.0.1" />
3940
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
4041
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
4142
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

‎src/Dotnet.Script.Core/Interactive/InteractiveRunner.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Interactive/InteractiveRunner.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private string ReadInput()
126126

127127
while (true)
128128
{
129-
var line = Console.In.ReadLine();
129+
var line = Console.ReadLine();
130130
input.AppendLine(line);
131131

132132
var syntaxTree = SyntaxFactory.ParseSyntaxTree(input.ToString(), ParseOptions);

‎src/Dotnet.Script.Core/ScriptConsole.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/ScriptConsole.cs
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System;
22
using System.IO;
3+
using RL = System.ReadLine;
34

45
namespace Dotnet.Script.Core
56
{
67
public class ScriptConsole
78
{
8-
public static readonly ScriptConsole Default = new ScriptConsole(Console.Out, Console.In, Console.Error);
9+
public static readonly ScriptConsole Default = new ScriptConsole(Console.Out, null, Console.Error);
910

1011
public virtual TextWriter Error { get; }
1112
public virtual TextWriter Out { get; }
@@ -39,8 +40,18 @@ public virtual void WriteNormal(string value)
3940
Out.WriteLine(value.TrimEnd(Environment.NewLine.ToCharArray()));
4041
}
4142

43+
public virtual string ReadLine()
44+
{
45+
return In == null ? RL.Read() : In.ReadLine();
46+
}
47+
4248
public ScriptConsole(TextWriter output, TextReader input, TextWriter error)
4349
{
50+
if (input == null)
51+
{
52+
RL.HistoryEnabled = true;
53+
}
54+
4455
Out = output;
4556
Error = error;
4657
In = input;

‎src/Dotnet.Script.Core/ScriptPublisher.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/ScriptPublisher.cs
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Dotnet.Script.DependencyModel.Environment;
1+
using Dotnet.Script.Core.Internal;
2+
using Dotnet.Script.DependencyModel.Environment;
23
using Dotnet.Script.DependencyModel.Logging;
34
using Dotnet.Script.DependencyModel.Process;
45
using Dotnet.Script.DependencyModel.ProjectSystem;
@@ -72,15 +73,15 @@ public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory l
7273
const string AssemblyName = "scriptAssembly";
7374

7475
var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath));
75-
var tempProjectDirecory = Path.GetDirectoryName(tempProjectPath);
76+
var tempProjectDirectory = Path.GetDirectoryName(tempProjectPath);
7677

77-
var scriptAssemblyPath = CreateScriptAssembly<TReturn, THost>(context, tempProjectDirecory, AssemblyName);
78+
var scriptAssemblyPath = CreateScriptAssembly<TReturn, THost>(context, tempProjectDirectory, AssemblyName);
7879
var projectFile = new ProjectFile(File.ReadAllText(tempProjectPath));
7980
projectFile.PackageReferences.Add(new PackageReference("Microsoft.CodeAnalysis.Scripting", ScriptingVersion));
8081
projectFile.AssemblyReferences.Add(new AssemblyReference(scriptAssemblyPath));
8182
projectFile.Save(tempProjectPath);
8283

83-
CopyProgramTemplate(tempProjectDirecory);
84+
CopyProgramTemplate(tempProjectDirectory);
8485

8586
var commandRunner = new CommandRunner(logFactory);
8687
// todo: may want to add ability to return dotnet.exe errors

‎src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private void ReportThatNewVersionIsAvailable(VersionInfo latestVersion)
7474
var updateInfo = new StringBuilder();
7575
updateInfo.AppendLine($"Version {latestVersion} is now available");
7676
updateInfo.AppendLine("Depending on how dotnet-script was installed, execute on of the following commands to update.");
77-
updateInfo.AppendLine("Global tool : dotnet tool update dotnet-script");
77+
updateInfo.AppendLine("Global tool : dotnet tool update dotnet-script -g");
7878
if (ScriptEnvironment.Default.IsWindows)
7979
{
8080
updateInfo.AppendLine("Chocolatey : choco upgrade Dotnet.Script");
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Dotnet.Script.Tests")]

‎src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<ItemGroup>
2727
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
28+
<PackageReference Include="NuGet.Configuration" Version="4.8.0" />
2829
</ItemGroup>
2930

3031
</Project>
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using NuGet.Configuration;
2+
using System.Collections.Generic;
3+
4+
namespace Dotnet.Script.DependencyModel.ProjectSystem
5+
{
6+
internal static class NuGetUtilities
7+
{
8+
struct NuGetConfigSection
9+
{
10+
public string Name;
11+
public HashSet<string> KeysForPathValues;
12+
public bool AreAllValuesPaths;
13+
}
14+
15+
static readonly NuGetConfigSection[] NuGetSections =
16+
{
17+
new NuGetConfigSection { Name = "config", KeysForPathValues = new HashSet<string> { "globalPackagesFolder", "repositoryPath" } },
18+
new NuGetConfigSection { Name = "bindingRedirects" },
19+
new NuGetConfigSection { Name = "packageRestore" },
20+
new NuGetConfigSection { Name = "solution" },
21+
new NuGetConfigSection { Name = "packageSources", AreAllValuesPaths = true },
22+
new NuGetConfigSection { Name = "packageSourceCredentials" },
23+
new NuGetConfigSection { Name = "apikeys" },
24+
new NuGetConfigSection { Name = "disabledPackageSources" },
25+
new NuGetConfigSection { Name = "activePackageSource" },
26+
};
27+
28+
// Create a NuGet file containing all properties with resolved absolute paths
29+
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
30+
{
31+
var settings = Settings.LoadDefaultSettings(pathToEvaluate);
32+
var target = new Settings(targetDirectory);
33+
34+
var valuesToSet = new List<SettingValue>();
35+
foreach (var section in NuGetSections)
36+
{
37+
// Resolve properly path values
38+
valuesToSet.Clear();
39+
if (section.AreAllValuesPaths)
40+
{
41+
// All values are paths
42+
var values = settings.GetSettingValues(section.Name, true);
43+
valuesToSet.AddRange(values);
44+
}
45+
else
46+
{
47+
var values = settings.GetSettingValues(section.Name, false);
48+
if (section.KeysForPathValues != null)
49+
{
50+
// Some values are path
51+
foreach (var value in values)
52+
{
53+
if (section.KeysForPathValues.Contains(value.Key))
54+
{
55+
var val = settings.GetValue(section.Name, value.Key, true);
56+
value.Value = val;
57+
}
58+
59+
valuesToSet.Add(value);
60+
}
61+
}
62+
else
63+
// All values are not path
64+
valuesToSet.AddRange(values);
65+
}
66+
target.SetValues(section.Name, valuesToSet);
67+
}
68+
}
69+
}
70+
}

‎src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs
+11-10Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using Dotnet.Script.DependencyModel.Environment;
66
using Dotnet.Script.DependencyModel.Logging;
7+
using NuGet.Configuration;
78

89
namespace Dotnet.Script.DependencyModel.ProjectSystem
910
{
@@ -60,7 +61,7 @@ public string CreateProjectForRepl(string code, string targetDirectory, string d
6061

6162
LogProjectFileInfo(pathToProjectFile);
6263

63-
CopyNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
64+
EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
6465
return pathToProjectFile;
6566
}
6667

@@ -101,7 +102,7 @@ private string SaveProjectFileFromScriptFiles(string targetDirectory, string def
101102

102103
LogProjectFileInfo(pathToProjectFile);
103104

104-
CopyNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
105+
EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
105106
return pathToProjectFile;
106107
}
107108

@@ -120,15 +121,15 @@ public ProjectFile CreateProjectFileFromScriptFiles(string defaultTargetFramewor
120121
return projectFile;
121122
}
122123

123-
private void CopyNuGetConfigFile(string targetDirectory, string pathToProjectFileFolder)
124+
private void EvaluateAndGenerateNuGetConfigFile(string targetDirectory, string pathToProjectFileFolder)
124125
{
125-
var pathToNuGetConfigFile = Path.Combine(targetDirectory, "NuGet.Config");
126-
if (File.Exists(pathToNuGetConfigFile))
127-
{
128-
var pathToDestinationNuGetConfigFile = Path.Combine(pathToProjectFileFolder, "NuGet.Config");
129-
_logger.Debug($"Copying {pathToNuGetConfigFile} to {pathToDestinationNuGetConfigFile}");
130-
File.Copy(pathToNuGetConfigFile, Path.Combine(pathToProjectFileFolder, "NuGet.Config"), true);
131-
}
126+
var pathToDestinationNuGetConfigFile = Path.Combine(pathToProjectFileFolder, Settings.DefaultSettingsFileName);
127+
128+
if (File.Exists(pathToDestinationNuGetConfigFile))
129+
File.Delete(pathToDestinationNuGetConfigFile);
130+
131+
_logger.Debug($"Generating NuGet config evaluated at {targetDirectory} to {pathToDestinationNuGetConfigFile}");
132+
NuGetUtilities.CreateNuGetConfigFromLocation(targetDirectory, pathToProjectFileFolder);
132133
}
133134

134135
public static string GetPathToProjectFile(string targetDirectory)

‎src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private static string GetFullPath(string relativePath, IEnumerable<string> nuget
188188
}
189189
}
190190
string message = $@"The requested dependency ({relativePath}) was not found in the global Nuget cache(s).
191-
. Try executing/publishing the script again with the '--nocache' option";
191+
. Try executing/publishing the script again with the '--no-cache' option";
192192
throw new InvalidOperationException(message);
193193
}
194194

‎src/Dotnet.Script.DependencyModel/ScriptPackage/ScriptFilesDependencyResolver.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/ScriptPackage/ScriptFilesDependencyResolver.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private static string GetPackageFullPath(string packagePath, string[] nugetPacka
133133
}
134134

135135
string message = $@"The requested script package path ({packagePath}) was not found in the global Nuget cache(s).
136-
. Try executing/publishing the script again with the '--nocache' option";
136+
. Try executing/publishing the script again with the '--no-cache' option";
137137

138138
throw new InvalidOperationException(message);
139139
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.