From 3a8404eb82c427692977f897b78315aaf3cec5fc Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 19 Jun 2019 15:51:12 +0200 Subject: [PATCH 1/5] Use ProjectFileInfo to return config path and project file path --- .../CompilationDependencyResolver.cs | 8 ++-- .../Context/CachedRestorer.cs | 12 +++--- .../Context/DotnetRestorer.cs | 9 ++-- .../Context/IRestorer.cs | 7 +++- .../Context/ProfiledRestorer.cs | 7 ++-- .../ProjectSystem/NuGetUtilities.cs | 7 ++++ .../ProjectSystem/ScriptProjectProvider.cs | 28 +++++++++---- .../Runtime/RuntimeDependencyResolver.cs | 24 +++++------ .../CachedRestorerTests.cs | 42 +++++++++++-------- .../ScriptProjectProviderTests.cs | 17 ++------ src/omnisharp.json | 9 ++++ 11 files changed, 101 insertions(+), 69 deletions(-) create mode 100644 src/omnisharp.json diff --git a/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs b/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs index d0892603..dbad977f 100644 --- a/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs +++ b/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs @@ -35,9 +35,9 @@ public CompilationDependencyResolver(LogFactory logFactory) public IEnumerable GetDependencies(string targetDirectory, IEnumerable scriptFiles, bool enableScriptNugetReferences, string defaultTargetFramework = "net46") { - var pathToProjectFile = _scriptProjectProvider.CreateProject(targetDirectory, scriptFiles,defaultTargetFramework, enableScriptNugetReferences); - _restorer.Restore(pathToProjectFile, packageSources: Array.Empty()); - var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json"); + var projectFileInfo = _scriptProjectProvider.CreateProject(targetDirectory, scriptFiles, defaultTargetFramework, enableScriptNugetReferences); + _restorer.Restore(projectFileInfo, packageSources: Array.Empty()); + var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json"); var dependencyContext = _scriptDependencyContextReader.ReadDependencyContext(pathToAssetsFile); var result = new List(); foreach (var scriptDependency in dependencyContext.Dependencies) @@ -51,7 +51,7 @@ public IEnumerable GetDependencies(string targetDirectory private static IRestorer CreateRestorer(LogFactory logFactory) { var commandRunner = new CommandRunner(logFactory); - return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory),logFactory); + return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory); } } } \ No newline at end of file diff --git a/src/Dotnet.Script.DependencyModel/Context/CachedRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/CachedRestorer.cs index d1aa0b15..f9fc29a3 100644 --- a/src/Dotnet.Script.DependencyModel/Context/CachedRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/CachedRestorer.cs @@ -28,17 +28,17 @@ public CachedRestorer(IRestorer restorer, LogFactory logFactory) public bool CanRestore => _restorer.CanRestore; /// - public void Restore(string pathToProjectFile, string[] packageSources) + public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) { - var projectFile = new ProjectFile(File.ReadAllText(pathToProjectFile)); - var pathToCachedProjectFile = $"{pathToProjectFile}.cache"; + var projectFile = new ProjectFile(File.ReadAllText(projectFileInfo.Path)); + var pathToCachedProjectFile = $"{projectFileInfo.Path}.cache"; if (File.Exists(pathToCachedProjectFile)) { _logger.Debug($"Found cached csproj file at: {pathToCachedProjectFile}"); var cachedProjectFile = new ProjectFile(File.ReadAllText(pathToCachedProjectFile)); if (projectFile.Equals(cachedProjectFile)) { - _logger.Debug($"Skipping restore. {pathToProjectFile} and {pathToCachedProjectFile} are identical."); + _logger.Debug($"Skipping restore. {projectFileInfo.Path} and {pathToCachedProjectFile} are identical."); return; } else @@ -55,7 +55,7 @@ public void Restore(string pathToProjectFile, string[] packageSources) void RestoreAndCacheProjectFile() { - _restorer.Restore(pathToProjectFile, packageSources); + _restorer.Restore(projectFileInfo, packageSources); if (projectFile.IsCacheable) { _logger.Debug($"Caching project file : {pathToCachedProjectFile}"); @@ -63,7 +63,7 @@ void RestoreAndCacheProjectFile() } else { - _logger.Warning($"Unable to cache {pathToProjectFile}. For caching and optimal performance, ensure that the script(s) references Nuget packages with a pinned version."); + _logger.Warning($"Unable to cache {projectFileInfo.Path}. For caching and optimal performance, ensure that the script(s) references Nuget packages with a pinned version."); } } } diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index 53b54cb1..66a31d2b 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -1,6 +1,7 @@ using Dotnet.Script.DependencyModel.Environment; using Dotnet.Script.DependencyModel.Logging; using Dotnet.Script.DependencyModel.Process; +using Dotnet.Script.DependencyModel.ProjectSystem; using System; using System.Linq; @@ -19,18 +20,18 @@ public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory) _scriptEnvironment = ScriptEnvironment.Default; } - public void Restore(string pathToProjectFile, string[] packageSources) + public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) { var packageSourcesArgument = CreatePackageSourcesArguments(); var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier; - _logger.Debug($"Restoring {pathToProjectFile} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}"); - var exitcode = _commandRunner.Execute("dotnet", $"restore \"{pathToProjectFile}\" -r {runtimeIdentifier} {packageSourcesArgument}"); + _logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}"); + var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument}"); //var exitcode = _commandRunner.Execute("dotnet", $"restore \"{pathToProjectFile}\" {packageSourcesArgument}"); if (exitcode != 0) { // We must throw here, otherwise we may incorrectly run with the old 'project.assets.json' - throw new Exception($"Unable to restore packages from '{pathToProjectFile}'. Make sure that all script files contains valid NuGet references"); + throw new Exception($"Unable to restore packages from '{projectFileInfo.Path}'. Make sure that all script files contains valid NuGet references"); } string CreatePackageSourcesArguments() diff --git a/src/Dotnet.Script.DependencyModel/Context/IRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/IRestorer.cs index 6c00a428..72e0591b 100644 --- a/src/Dotnet.Script.DependencyModel/Context/IRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/IRestorer.cs @@ -1,4 +1,6 @@ -namespace Dotnet.Script.DependencyModel.Context +using Dotnet.Script.DependencyModel.ProjectSystem; + +namespace Dotnet.Script.DependencyModel.Context { /// /// Represents a class that is capable of restoring a project file. @@ -10,7 +12,8 @@ public interface IRestorer /// /// /// A list of packages sources to be used when restoring NuGet packages. - void Restore(string pathToProjectFile, string[] packageSources); + /// The path to the NuGet config file to be used when restoring. + void Restore(ProjectFileInfo projectFileInfo, string[] packageSources); /// /// Gets a value that indicates if this is available on the system. diff --git a/src/Dotnet.Script.DependencyModel/Context/ProfiledRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/ProfiledRestorer.cs index f0024a48..5f7f9031 100644 --- a/src/Dotnet.Script.DependencyModel/Context/ProfiledRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/ProfiledRestorer.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using Dotnet.Script.DependencyModel.Logging; +using Dotnet.Script.DependencyModel.ProjectSystem; namespace Dotnet.Script.DependencyModel.Context { @@ -16,11 +17,11 @@ public ProfiledRestorer(IRestorer restorer, LogFactory logFactory) public bool CanRestore => _restorer.CanRestore; - public void Restore(string pathToProjectFile, string[] packageSources) + public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) { var stopwatch = Stopwatch.StartNew(); - _restorer.Restore(pathToProjectFile, packageSources); - _logger.Debug($"Restoring {pathToProjectFile} took {stopwatch.ElapsedMilliseconds}ms"); + _restorer.Restore(projectFileInfo, packageSources); + _logger.Debug($"Restoring {projectFileInfo.Path} took {stopwatch.ElapsedMilliseconds}ms"); } } } diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs index c45b98ce..da51f7fd 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs @@ -6,6 +6,13 @@ namespace Dotnet.Script.DependencyModel.ProjectSystem { internal static class NuGetUtilities { + + public static string GetNearestConfigPath(string pathToEvaluate) + { + var settings = Settings.LoadDefaultSettings(pathToEvaluate); + return settings.GetConfigFilePaths().FirstOrDefault(); + } + public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory) { var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate); diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs index 7970019f..d3293bbe 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs @@ -27,7 +27,7 @@ private ScriptProjectProvider(ScriptParser scriptParser, ScriptFilesResolver scr { } - public string CreateProjectForRepl(string code, string targetDirectory, string defaultTargetFramework = "net46") + public ProjectFileInfo CreateProjectForRepl(string code, string targetDirectory, string defaultTargetFramework = "net46") { var scriptFiles = _scriptFilesResolver.GetScriptFilesFromCode(code); targetDirectory = Path.Combine(targetDirectory, "interactive"); @@ -62,7 +62,9 @@ public string CreateProjectForRepl(string code, string targetDirectory, string d LogProjectFileInfo(pathToProjectFile); EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile)); - return pathToProjectFile; + //return ret pathToProjectFile; + + return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory)); } private void LogProjectFileInfo(string pathToProjectFile) @@ -72,12 +74,12 @@ private void LogProjectFileInfo(string pathToProjectFile) _logger.Debug(content); } - public string CreateProject(string targetDirectory, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false) + public ProjectFileInfo CreateProject(string targetDirectory, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false) { return CreateProject(targetDirectory, Directory.GetFiles(targetDirectory, "*.csx", SearchOption.AllDirectories), defaultTargetFramework, enableNuGetScriptReferences); } - public string CreateProject(string targetDirectory, IEnumerable scriptFiles, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false) + public ProjectFileInfo CreateProject(string targetDirectory, IEnumerable scriptFiles, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false) { if (scriptFiles == null || !scriptFiles.Any()) { @@ -95,14 +97,14 @@ public string CreateProject(string targetDirectory, IEnumerable scriptFi return SaveProjectFileFromScriptFiles(targetDirectory, defaultTargetFramework, scriptFiles.ToArray()); } - public string CreateProjectForScriptFile(string scriptFile) + public ProjectFileInfo CreateProjectForScriptFile(string scriptFile) { _logger.Debug($"Creating project file for {scriptFile}"); var scriptFiles = _scriptFilesResolver.GetScriptFiles(scriptFile); return SaveProjectFileFromScriptFiles(Path.GetDirectoryName(scriptFile), _scriptEnvironment.TargetFramework, scriptFiles.ToArray()); } - private string SaveProjectFileFromScriptFiles(string targetDirectory, string defaultTargetFramework, string[] csxFiles) + private ProjectFileInfo SaveProjectFileFromScriptFiles(string targetDirectory, string defaultTargetFramework, string[] csxFiles) { ProjectFile projectFile = CreateProjectFileFromScriptFiles(defaultTargetFramework, csxFiles); @@ -112,7 +114,7 @@ private string SaveProjectFileFromScriptFiles(string targetDirectory, string def LogProjectFileInfo(pathToProjectFile); EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile)); - return pathToProjectFile; + return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory)); } public ProjectFile CreateProjectFileFromScriptFiles(string defaultTargetFramework, string[] csxFiles) @@ -148,4 +150,16 @@ public static string GetPathToProjectFile(string targetDirectory) return pathToProjectFile; } } + + public class ProjectFileInfo + { + public ProjectFileInfo(string path, string configPath) + { + Path = path; + ConfigPath = configPath; + } + + public string Path { get; } + public string ConfigPath { get; } + } } \ No newline at end of file diff --git a/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs b/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs index 9efd3cfd..0df4f405 100644 --- a/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs +++ b/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs @@ -27,29 +27,29 @@ public RuntimeDependencyResolver(ScriptProjectProvider scriptProjectProvider, Lo _restorer = CreateRestorer(logFactory, useRestoreCache); } - public RuntimeDependencyResolver(LogFactory logFactory, bool useRestoreCache) : this(new ScriptProjectProvider(logFactory), logFactory, ScriptEnvironment.Default, useRestoreCache) - { + public RuntimeDependencyResolver(LogFactory logFactory, bool useRestoreCache) : this(new ScriptProjectProvider(logFactory), logFactory, ScriptEnvironment.Default, useRestoreCache) + { - } + } private static IRestorer CreateRestorer(LogFactory logFactory, bool useRestoreCache) { var commandRunner = new CommandRunner(logFactory); if (useRestoreCache) { - return new ProfiledRestorer(new CachedRestorer(new DotnetRestorer(commandRunner, logFactory),logFactory),logFactory); + return new ProfiledRestorer(new CachedRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory), logFactory); } else { - return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory),logFactory); + return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory); } } public IEnumerable GetDependencies(string scriptFile, string[] packageSources) { - var pathToProjectFile = _scriptProjectProvider.CreateProjectForScriptFile(scriptFile); - _restorer.Restore(pathToProjectFile, packageSources); - var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json"); + var projectFileInfo = _scriptProjectProvider.CreateProjectForScriptFile(scriptFile); + _restorer.Restore(projectFileInfo, packageSources); + var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json"); return GetDependenciesInternal(pathToAssetsFile); } @@ -61,9 +61,9 @@ public IEnumerable GetDependenciesForLibrary(string pathToLib public IEnumerable GetDependenciesForCode(string targetDirectory, ScriptMode scriptMode, string[] packageSources, string code = null) { - var pathToProjectFile = _scriptProjectProvider.CreateProjectForRepl(code, Path.Combine(targetDirectory, scriptMode.ToString()), ScriptEnvironment.Default.TargetFramework); - _restorer.Restore(pathToProjectFile, packageSources); - var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json"); + var projectFileInfo = _scriptProjectProvider.CreateProjectForRepl(code, Path.Combine(targetDirectory, scriptMode.ToString()), ScriptEnvironment.Default.TargetFramework); + _restorer.Restore(projectFileInfo, packageSources); + var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json"); return GetDependenciesInternal(pathToAssetsFile); } @@ -74,7 +74,7 @@ private IEnumerable GetDependenciesInternal(string pathToAsse foreach (var scriptDependency in context.Dependencies) { var runtimeAssemblies = scriptDependency.RuntimeDependencyPaths.Select(rdp => new RuntimeAssembly(AssemblyName.GetAssemblyName(rdp), rdp)).ToList(); - var runtimeDependency = new RuntimeDependency(scriptDependency.Name, scriptDependency.Version,runtimeAssemblies, scriptDependency.NativeAssetPaths,scriptDependency.ScriptPaths); + var runtimeDependency = new RuntimeDependency(scriptDependency.Name, scriptDependency.Version, runtimeAssemblies, scriptDependency.NativeAssetPaths, scriptDependency.ScriptPaths); result.Add(runtimeDependency); } diff --git a/src/Dotnet.Script.Tests/CachedRestorerTests.cs b/src/Dotnet.Script.Tests/CachedRestorerTests.cs index 405e5672..2fb762c9 100644 --- a/src/Dotnet.Script.Tests/CachedRestorerTests.cs +++ b/src/Dotnet.Script.Tests/CachedRestorerTests.cs @@ -25,21 +25,23 @@ public void ShouldUseCacheWhenAllPackagedArePinned() using (var projectFolder = new DisposableFolder()) { - var pathToProjectFile = Path.Combine(projectFolder.Path ,"script.csproj"); - var pathToCachedProjectFile = Path.Combine(projectFolder.Path ,"script.csproj.cache"); + var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); + var pathToCachedProjectFile = Path.Combine(projectFolder.Path, "script.csproj.cache"); var projectFile = new ProjectFile(); projectFile.PackageReferences.Add(new PackageReference("SomePackage", "1.2.3")); projectFile.PackageReferences.Add(new PackageReference("AnotherPackage", "3.2.1")); projectFile.Save(pathToProjectFile); - cachedRestorer.Restore(pathToProjectFile, NoPackageSources); - restorerMock.Verify(m => m.Restore(pathToProjectFile, NoPackageSources), Times.Once); + var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); + + cachedRestorer.Restore(projectFileInfo, NoPackageSources); + restorerMock.Verify(m => m.Restore(projectFileInfo, NoPackageSources), Times.Once); Assert.True(Directory.GetFiles(projectFolder.Path).Contains(pathToCachedProjectFile)); restorerMock.Reset(); - cachedRestorer.Restore(pathToProjectFile, NoPackageSources); - restorerMock.Verify(m => m.Restore(pathToProjectFile, NoPackageSources), Times.Never); + cachedRestorer.Restore(projectFileInfo, NoPackageSources); + restorerMock.Verify(m => m.Restore(projectFileInfo, NoPackageSources), Times.Never); Assert.True(Directory.GetFiles(projectFolder.Path).Contains(pathToCachedProjectFile)); } } @@ -53,21 +55,23 @@ public void ShouldNotUseCacheWhenPackagesAreNotPinned() using (var projectFolder = new DisposableFolder()) { var projectFile = new ProjectFile(); - var pathToProjectFile = Path.Combine(projectFolder.Path ,"script.csproj"); - var pathToCachedProjectFile = Path.Combine(projectFolder.Path ,"script.csproj.cache"); + var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); + var pathToCachedProjectFile = Path.Combine(projectFolder.Path, "script.csproj.cache"); projectFile.PackageReferences.Add(new PackageReference("SomePackage", "1.2.3")); projectFile.PackageReferences.Add(new PackageReference("AnotherPackage", "3.2")); projectFile.Save(pathToProjectFile); - cachedRestorer.Restore(pathToProjectFile, NoPackageSources); + var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); + + cachedRestorer.Restore(projectFileInfo, NoPackageSources); - restorerMock.Verify(m => m.Restore(pathToProjectFile, NoPackageSources), Times.Once); + restorerMock.Verify(m => m.Restore(projectFileInfo, NoPackageSources), Times.Once); Assert.False(Directory.GetFiles(projectFolder.Path).Contains(pathToCachedProjectFile)); restorerMock.Reset(); - cachedRestorer.Restore(pathToProjectFile, NoPackageSources); - restorerMock.Verify(m => m.Restore(pathToProjectFile, NoPackageSources), Times.Once); + cachedRestorer.Restore(projectFileInfo, NoPackageSources); + restorerMock.Verify(m => m.Restore(projectFileInfo, NoPackageSources), Times.Once); Assert.False(Directory.GetFiles(projectFolder.Path).Contains(pathToCachedProjectFile)); } } @@ -81,24 +85,26 @@ public void ShouldNotCacheWhenProjectFilesAreNotEqual() using (var projectFolder = new DisposableFolder()) { var projectFile = new ProjectFile(); - var pathToProjectFile = Path.Combine(projectFolder.Path ,"script.csproj"); - var pathToCachedProjectFile = Path.Combine(projectFolder.Path ,"script.csproj.cache"); + var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); + var pathToCachedProjectFile = Path.Combine(projectFolder.Path, "script.csproj.cache"); projectFile.PackageReferences.Add(new PackageReference("SomePackage", "1.2.3")); projectFile.PackageReferences.Add(new PackageReference("AnotherPackage", "1.2.3")); projectFile.Save(pathToProjectFile); - cachedRestorer.Restore(pathToProjectFile, NoPackageSources); + var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); + + cachedRestorer.Restore(projectFileInfo, NoPackageSources); - restorerMock.Verify(m => m.Restore(pathToProjectFile, NoPackageSources), Times.Once); + restorerMock.Verify(m => m.Restore(projectFileInfo, NoPackageSources), Times.Once); Assert.True(Directory.GetFiles(projectFolder.Path).Contains(pathToCachedProjectFile)); restorerMock.Reset(); projectFile.PackageReferences.Add(new PackageReference("YetAnotherPackage", "1.2.3")); projectFile.Save(pathToProjectFile); - cachedRestorer.Restore(pathToProjectFile, NoPackageSources); + cachedRestorer.Restore(projectFileInfo, NoPackageSources); - restorerMock.Verify(m => m.Restore(pathToProjectFile, NoPackageSources), Times.Once); + restorerMock.Verify(m => m.Restore(projectFileInfo, NoPackageSources), Times.Once); Assert.True(Directory.GetFiles(projectFolder.Path).Contains(pathToCachedProjectFile)); } } diff --git a/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs b/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs index ee52347b..e7271d75 100644 --- a/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs +++ b/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs @@ -10,7 +10,7 @@ namespace Dotnet.Script.Tests { [Collection("IntegrationTests")] public class ScriptProjectProviderTests - { + { private readonly ScriptEnvironment _scriptEnvironment; public ScriptProjectProviderTests(ITestOutputHelper testOutputHelper) @@ -19,30 +19,21 @@ public ScriptProjectProviderTests(ITestOutputHelper testOutputHelper) _scriptEnvironment = ScriptEnvironment.Default; } - [Fact] - public void ShouldCopyLocalNuGetConfig() - { - var provider = CreateProvider(); - var pathToProjectFile = provider.CreateProject(TestPathUtils.GetPathToTestFixtureFolder("LocalNuGetConfig"), _scriptEnvironment.TargetFramework, true); - var pathToProjectFileFolder = Path.GetDirectoryName(pathToProjectFile); - Assert.True(File.Exists(Path.Combine(pathToProjectFileFolder,"NuGet.Config"))); - } - [Fact] public void ShouldLogProjectFileContent() { - StringBuilder log = new StringBuilder(); + StringBuilder log = new StringBuilder(); var provider = new ScriptProjectProvider(type => ((level, message, exception) => log.AppendLine(message))); provider.CreateProject(TestPathUtils.GetPathToTestFixtureFolder("HelloWorld"), _scriptEnvironment.TargetFramework, true); var output = log.ToString(); - Assert.Contains("",output); + Assert.Contains("", output); } private ScriptProjectProvider CreateProvider() { - ScriptProjectProvider provider = new ScriptProjectProvider(TestOutputHelper.CreateTestLogFactory()); + ScriptProjectProvider provider = new ScriptProjectProvider(TestOutputHelper.CreateTestLogFactory()); return provider; } } diff --git a/src/omnisharp.json b/src/omnisharp.json new file mode 100644 index 00000000..922da146 --- /dev/null +++ b/src/omnisharp.json @@ -0,0 +1,9 @@ +{ + "fileOptions": { + "systemExcludeSearchPatterns": [ + "**/TestFixtures/**/*.csx", + "**/ScriptPackages/**/*.csx" + ], + "userExcludeSearchPatterns": [] + } +} From 1be69e3ace6835e24c687a1303194118e4a3b60f Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 19 Jun 2019 23:07:35 +0200 Subject: [PATCH 2/5] Added relative test and removed dead code --- .../Context/DotnetRestorer.cs | 12 +- .../ProjectSystem/NuGetUtilities.cs | 57 ----- .../ProjectSystem/ScriptProjectProvider.cs | 21 +- .../TestPathUtils.cs | 7 +- .../NuGetUtilitiesTests.cs | 225 ------------------ .../ScriptExecutionTests.cs | 41 +++- 6 files changed, 55 insertions(+), 308 deletions(-) delete mode 100644 src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index 66a31d2b..415cfe03 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -23,11 +23,11 @@ public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory) public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) { var packageSourcesArgument = CreatePackageSourcesArguments(); + var configFileArgument = CreateConfigFileArgument(); var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier; _logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}"); - var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument}"); - //var exitcode = _commandRunner.Execute("dotnet", $"restore \"{pathToProjectFile}\" {packageSourcesArgument}"); + var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}"); if (exitcode != 0) { // We must throw here, otherwise we may incorrectly run with the old 'project.assets.json' @@ -41,6 +41,14 @@ string CreatePackageSourcesArguments() : packageSources.Select(s => $"-s {s}") .Aggregate((current, next) => $"{current} {next}"); } + + string CreateConfigFileArgument() + { + return string.IsNullOrWhiteSpace(projectFileInfo.NuGetConfigFile) + ? string.Empty + : $"--configfile {projectFileInfo.NuGetConfigFile}"; + + } } public bool CanRestore => true; diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs index da51f7fd..7e5637e9 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs @@ -1,71 +1,14 @@ using NuGet.Configuration; -using System.Collections.Generic; using System.Linq; namespace Dotnet.Script.DependencyModel.ProjectSystem { internal static class NuGetUtilities { - public static string GetNearestConfigPath(string pathToEvaluate) { var settings = Settings.LoadDefaultSettings(pathToEvaluate); return settings.GetConfigFilePaths().FirstOrDefault(); } - - public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory) - { - var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate); - var targetSettings = new Settings(targetDirectory); - - CopySection(sourceSettings, targetSettings, "config"); - CopySection(sourceSettings, targetSettings, "bindingRedirects"); - CopySection(sourceSettings, targetSettings, "packageRestore"); - CopySection(sourceSettings, targetSettings, "solution"); - CopySection(sourceSettings, targetSettings, "packageSources"); - CopySection(sourceSettings, targetSettings, "packageSourceCredentials"); - CopySection(sourceSettings, targetSettings, "apikeys"); - CopySection(sourceSettings, targetSettings, "disabledPackageSources"); - CopySection(sourceSettings, targetSettings, "activePackageSource"); - - targetSettings.SaveToDisk(); - } - - private static void CopySection(ISettings sourceSettings, ISettings targetSettings, string sectionName) - { - var existingAddItems = sourceSettings.GetSection(sectionName)?.Items.Where(item => item is object && (item is SourceItem || item is AddItem) && item.ElementName.ToLowerInvariant() == "add").Cast(); - - if (existingAddItems == null) - { - return; - } - - foreach (var addItem in existingAddItems) - { - if (ShouldResolvePath(sectionName, addItem.Key)) - { - targetSettings.AddOrUpdate(sectionName, new AddItem(addItem.Key, addItem.GetValueAsPath())); - } - else - { - targetSettings.AddOrUpdate(sectionName, addItem); - } - } - } - - private static bool ShouldResolvePath(string sectionName, string key) - { - if (sectionName == "packageSources") - { - return true; - } - - if (sectionName == "config") - { - return key == "globalPackagesFolder" || key == "repositoryPath"; - } - - return false; - } } } diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs index d3293bbe..012c3889 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs @@ -61,9 +61,6 @@ public ProjectFileInfo CreateProjectForRepl(string code, string targetDirectory, LogProjectFileInfo(pathToProjectFile); - EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile)); - //return ret pathToProjectFile; - return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory)); } @@ -113,7 +110,6 @@ private ProjectFileInfo SaveProjectFileFromScriptFiles(string targetDirectory, s LogProjectFileInfo(pathToProjectFile); - EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile)); return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory)); } @@ -132,17 +128,6 @@ public ProjectFile CreateProjectFileFromScriptFiles(string defaultTargetFramewor return projectFile; } - private void EvaluateAndGenerateNuGetConfigFile(string targetDirectory, string pathToProjectFileFolder) - { - var pathToDestinationNuGetConfigFile = Path.Combine(pathToProjectFileFolder, Settings.DefaultSettingsFileName); - - if (File.Exists(pathToDestinationNuGetConfigFile)) - File.Delete(pathToDestinationNuGetConfigFile); - - _logger.Debug($"Generating NuGet config evaluated at {targetDirectory} to {pathToDestinationNuGetConfigFile}"); - NuGetUtilities.CreateNuGetConfigFromLocation(targetDirectory, pathToProjectFileFolder); - } - public static string GetPathToProjectFile(string targetDirectory) { var pathToProjectDirectory = FileUtils.CreateTempFolder(targetDirectory); @@ -153,13 +138,13 @@ public static string GetPathToProjectFile(string targetDirectory) public class ProjectFileInfo { - public ProjectFileInfo(string path, string configPath) + public ProjectFileInfo(string path, string nugetConfigFile) { Path = path; - ConfigPath = configPath; + NuGetConfigFile = nugetConfigFile; } public string Path { get; } - public string ConfigPath { get; } + public string NuGetConfigFile { get; } } } \ No newline at end of file diff --git a/src/Dotnet.Script.Shared.Tests/TestPathUtils.cs b/src/Dotnet.Script.Shared.Tests/TestPathUtils.cs index 5af88cbd..8ac96caf 100644 --- a/src/Dotnet.Script.Shared.Tests/TestPathUtils.cs +++ b/src/Dotnet.Script.Shared.Tests/TestPathUtils.cs @@ -42,8 +42,11 @@ public static string GetPathToGlobalPackagesFolder() public static void RemovePackageFromGlobalNugetCache(string packageName) { var pathToGlobalPackagesFolder = TestPathUtils.GetPathToGlobalPackagesFolder(); - var pathToAutoMapperPackage = Directory.GetDirectories(pathToGlobalPackagesFolder).Single(d => d.Contains(packageName, StringComparison.OrdinalIgnoreCase)); - FileUtils.RemoveDirectory(pathToAutoMapperPackage); + var pathToPackage = Directory.GetDirectories(pathToGlobalPackagesFolder).SingleOrDefault(d => d.Contains(packageName, StringComparison.OrdinalIgnoreCase)); + if (pathToPackage != null) + { + FileUtils.RemoveDirectory(pathToPackage); + } } } } \ No newline at end of file diff --git a/src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs b/src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs deleted file mode 100644 index 35c5baa8..00000000 --- a/src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs +++ /dev/null @@ -1,225 +0,0 @@ -using Dotnet.Script.DependencyModel.ProjectSystem; -using NuGet.Configuration; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Xunit; - -namespace Dotnet.Script.Tests -{ - using SettingsSection = Dictionary>; - using SettingsValues = Dictionary; - - public class NuGetUtilitiesTests - { - public static object[][] Args = - { - new object[] - { - @" - - - - - - - -", - new SettingsSection - { - { - "config", - new SettingsValues - { - { "dependencyVersion", "Highest" }, - { "globalPackagesFolder", @"{1}/packages" }, - { "repositoryPath", @"{0}../installed_packages" }, - { "http_proxy", @"http://company-squid:3128@contoso.com" }, - } - }, - } - }, - new object[] - { - @" - - - - -", - new SettingsSection - { - { - "bindingRedirects", - new SettingsValues - { - { "skip", "true" }, - } - }, - } - }, - new object[] - { - @" - - - - - -", - new SettingsSection - { - { - "packageRestore", - new SettingsValues - { - { "enabled", "true" }, - { "automatic", "true" }, - } - }, - } - }, - new object[] - { - @" - - - - -", - new SettingsSection - { - { - "solution", - new SettingsValues - { - { "disableSourceControlIntegration", "true" }, - } - }, - } - }, - new object[] - { - @" - - - - - - - -", - new SettingsSection - { - { - "packageSources", - new SettingsValues - { - { "nuget.org", "https://api.nuget.org/v3/index.json" }, - { "Contoso", "https://contoso.com/packages/" }, - { "Test Source", "{1}/packages" }, - { "Relative Test Source", "{0}../packages" }, - } - }, - } - }, - new object[] - { - @" - - - - -", - new SettingsSection - { - { - "apikeys", - new SettingsValues - { - { "https://MyRepo/ES/api/v2/package", "encrypted_api_key" }, - } - }, - } - }, - new object[] - { - @" - - - - -", - new SettingsSection - { - { - "disabledPackageSources", - new SettingsValues - { - { "Contoso", "true" }, - } - }, - } - }, - new object[] - { - @" - - - - -", - new SettingsSection - { - { - "activePackageSource", - new SettingsValues - { - { "nuget.org", "https://api.nuget.org/v3/index.json" }, - } - }, - } - }, - }; - - [Theory] - [MemberData(nameof(Args))] - public void ShouldGenerateEvaluatedNuGetConfigFile(string sourceNuGet, SettingsSection targetSettings) - { - using (var projectFolder = new DisposableFolder()) - { - // Generate files and directories - var sourceFolder = Path.Combine(projectFolder.Path, "Source"); - var sourceScript = Path.Combine(sourceFolder, "script.cs"); - var targetFolder = Path.Combine(projectFolder.Path, "Target"); - Directory.CreateDirectory(targetFolder); - Directory.CreateDirectory(sourceFolder); - - var rootTokens = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:" : string.Empty; - - var resolvedSourceNuGet = string.Format(sourceNuGet, rootTokens); - File.WriteAllText(Path.Combine(sourceFolder, Settings.DefaultSettingsFileName), resolvedSourceNuGet); - - // Evaluate and generate the NuGet config file - NuGetUtilities.CreateNuGetConfigFromLocation(sourceScript, targetFolder); - - // Validate the generated NuGet config file - var targetNuGetPath = Path.Combine(targetFolder, Settings.DefaultSettingsFileName); - Assert.True(File.Exists(targetNuGetPath), $"NuGet.config file was not generated at {targetNuGetPath}"); - - sourceFolder += Path.DirectorySeparatorChar; - var settings = new Settings(targetFolder); - foreach (var expectedSettings in targetSettings) - { - foreach (var expectedSetting in expectedSettings.Value) - { - var value = settings.GetSection(expectedSettings.Key).Items.Cast().First(i => i.Key == expectedSetting.Key); - var resolvedExpectedSetting = string.Format(expectedSetting.Value, sourceFolder, rootTokens); - Assert.Equal(resolvedExpectedSetting, value.Value); - } - } - } - } - } -} \ No newline at end of file diff --git a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index e19eaa73..9cfb7ec2 100644 --- a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs +++ b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs @@ -172,8 +172,8 @@ public void ShouldHandleIssue318() } [Theory] - [InlineData("release","false")] - [InlineData("debug","true")] + [InlineData("release", "false")] + [InlineData("debug", "true")] public void ShouldCompileScriptWithReleaseConfiguration(string configuration, string expected) { var result = ScriptTestRunner.Default.ExecuteFixture("Configuration", $"-c {configuration}"); @@ -307,14 +307,14 @@ public void ShouldHandleNuGetVersionRange() [Fact] public void ShouldThrowMeaningfulErrorMessageWhenDependencyIsNotFound() { - using(var libraryFolder = new DisposableFolder()) + using (var libraryFolder = new DisposableFolder()) { // Create a package that we can reference ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n SampleLibrary", libraryFolder.Path); ProcessHelper.RunAndCaptureOutput("dotnet", "pack", libraryFolder.Path); - using(var scriptFolder = new DisposableFolder()) + using (var scriptFolder = new DisposableFolder()) { var code = new StringBuilder(); code.AppendLine("#r \"nuget:SampleLibrary, 1.0.0\""); @@ -382,5 +382,38 @@ public TestClass() Assert.Contains("Hello World!", result.output); } } + + + [Fact] + public void ShouldHandleLocalNuGetConfigWithRelativePath() + { + TestPathUtils.RemovePackageFromGlobalNugetCache("NuGetConfigTestLibrary"); + + using (var packageLibraryFolder = new DisposableFolder()) + { + ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary", packageLibraryFolder.Path); + var projectFolder = Path.Combine(packageLibraryFolder.Path, "NuGetConfigTestLibrary"); + ProcessHelper.RunAndCaptureOutput("dotnet", $"pack -o {Path.Combine(packageLibraryFolder.Path, "packagePath")}", projectFolder); + string nugetConfig = @" + + + + + +> + "; + File.WriteAllText(Path.Combine(packageLibraryFolder.Path, "NuGet.Config"), nugetConfig); + + string script = @" +#r ""nuget:NuGetConfigTestLibrary, 1.0.0"" +WriteLine(""Success""); + "; + string pathToScriptFile = Path.Combine(packageLibraryFolder.Path, "testscript.csx"); + File.WriteAllText(pathToScriptFile, script); + + var result = ScriptTestRunner.Default.Execute(pathToScriptFile); + Assert.Contains("Success", result.output); + } + } } } From 23a607590252eda7138914827bc5c2855044d584 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 19 Jun 2019 23:19:18 +0200 Subject: [PATCH 3/5] Added test for NuGet.Config in parent folder --- .../ScriptExecutionTests.cs | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index 9cfb7ec2..0c9bc3c9 100644 --- a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs +++ b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs @@ -391,10 +391,50 @@ public void ShouldHandleLocalNuGetConfigWithRelativePath() using (var packageLibraryFolder = new DisposableFolder()) { - ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary", packageLibraryFolder.Path); - var projectFolder = Path.Combine(packageLibraryFolder.Path, "NuGetConfigTestLibrary"); - ProcessHelper.RunAndCaptureOutput("dotnet", $"pack -o {Path.Combine(packageLibraryFolder.Path, "packagePath")}", projectFolder); - string nugetConfig = @" + CreateTestPackage(packageLibraryFolder); + + string pathToScriptFile = CreateTestScript(packageLibraryFolder.Path); + + var result = ScriptTestRunner.Default.Execute(pathToScriptFile); + Assert.Contains("Success", result.output); + } + } + + [Fact] + public void ShouldHandleLocalNuGetConfigWithRelativePathInParentFolder() + { + TestPathUtils.RemovePackageFromGlobalNugetCache("NuGetConfigTestLibrary"); + + using (var packageLibraryFolder = new DisposableFolder()) + { + CreateTestPackage(packageLibraryFolder); + + var scriptFolder = Path.Combine(packageLibraryFolder.Path, "ScriptFolder"); + Directory.CreateDirectory(scriptFolder); + string pathToScriptFile = CreateTestScript(scriptFolder); + + var result = ScriptTestRunner.Default.Execute(pathToScriptFile); + Assert.Contains("Success", result.output); + } + } + + private static string CreateTestScript(string scriptFolder) + { + string script = @" +#r ""nuget:NuGetConfigTestLibrary, 1.0.0"" +WriteLine(""Success""); + "; + string pathToScriptFile = Path.Combine(scriptFolder, "testscript.csx"); + File.WriteAllText(pathToScriptFile, script); + return pathToScriptFile; + } + + private static void CreateTestPackage(DisposableFolder packageLibraryFolder) + { + ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary", packageLibraryFolder.Path); + var projectFolder = Path.Combine(packageLibraryFolder.Path, "NuGetConfigTestLibrary"); + ProcessHelper.RunAndCaptureOutput("dotnet", $"pack -o {Path.Combine(packageLibraryFolder.Path, "packagePath")}", projectFolder); + string nugetConfig = @" @@ -402,18 +442,7 @@ public void ShouldHandleLocalNuGetConfigWithRelativePath() > "; - File.WriteAllText(Path.Combine(packageLibraryFolder.Path, "NuGet.Config"), nugetConfig); - - string script = @" -#r ""nuget:NuGetConfigTestLibrary, 1.0.0"" -WriteLine(""Success""); - "; - string pathToScriptFile = Path.Combine(packageLibraryFolder.Path, "testscript.csx"); - File.WriteAllText(pathToScriptFile, script); - - var result = ScriptTestRunner.Default.Execute(pathToScriptFile); - Assert.Contains("Success", result.output); - } + File.WriteAllText(Path.Combine(packageLibraryFolder.Path, "NuGet.Config"), nugetConfig); } } } From 80c059c8dabe7712b57926dc0d1532fbb23fd31a Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 19 Jun 2019 23:26:51 +0200 Subject: [PATCH 4/5] Moved ProjectFileInfo out in a separate file --- .../ProjectSystem/ProjectFileInfo.cs | 30 +++++++++++++++++++ .../ProjectSystem/ScriptProjectProvider.cs | 12 -------- 2 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/Dotnet.Script.DependencyModel/ProjectSystem/ProjectFileInfo.cs diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/ProjectFileInfo.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/ProjectFileInfo.cs new file mode 100644 index 00000000..1e8a549f --- /dev/null +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/ProjectFileInfo.cs @@ -0,0 +1,30 @@ +namespace Dotnet.Script.DependencyModel.ProjectSystem +{ + /// + /// Contains information about the generated project file and + /// where to find the "nearest" NuGet.Config file. + /// + public class ProjectFileInfo + { + /// + /// Initializes a new instance of the class. + /// + /// The path to the generated project file to be used during restore. + /// The path to the nearest NuGet.Config file seen from the target script folder. + public ProjectFileInfo(string path, string nugetConfigFile) + { + Path = path; + NuGetConfigFile = nugetConfigFile; + } + + /// + /// Gets the path of the generated project file to be used during restore. + /// + public string Path { get; } + + /// + /// Gets the path to the nearest NuGet.Config file seen from the target script folder. + /// + public string NuGetConfigFile { get; } + } +} \ No newline at end of file diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs index 012c3889..8f1dd175 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs @@ -135,16 +135,4 @@ public static string GetPathToProjectFile(string targetDirectory) return pathToProjectFile; } } - - public class ProjectFileInfo - { - public ProjectFileInfo(string path, string nugetConfigFile) - { - Path = path; - NuGetConfigFile = nugetConfigFile; - } - - public string Path { get; } - public string NuGetConfigFile { get; } - } } \ No newline at end of file From 22a955579fb164865230f0fe4fe02e08e446306d Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Thu, 20 Jun 2019 11:10:33 +0200 Subject: [PATCH 5/5] Log the location of selected NuGet config file --- src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index 415cfe03..d073a5e2 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -26,7 +26,7 @@ public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) var configFileArgument = CreateConfigFileArgument(); var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier; - _logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}"); + _logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier} NugetConfigFile: {projectFileInfo.NuGetConfigFile}"); var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}"); if (exitcode != 0) {