Skip to content

Navigation Menu

Sign in
Appearance settings

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 3a8404e

Browse filesBrowse files
committed
Use ProjectFileInfo to return config path and project file path
1 parent 3c96c31 commit 3a8404e
Copy full SHA for 3a8404e

11 files changed

+101
-69
lines changed

‎src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public CompilationDependencyResolver(LogFactory logFactory)
3535

3636
public IEnumerable<CompilationDependency> GetDependencies(string targetDirectory, IEnumerable<string> scriptFiles, bool enableScriptNugetReferences, string defaultTargetFramework = "net46")
3737
{
38-
var pathToProjectFile = _scriptProjectProvider.CreateProject(targetDirectory, scriptFiles,defaultTargetFramework, enableScriptNugetReferences);
39-
_restorer.Restore(pathToProjectFile, packageSources: Array.Empty<string>());
40-
var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json");
38+
var projectFileInfo = _scriptProjectProvider.CreateProject(targetDirectory, scriptFiles, defaultTargetFramework, enableScriptNugetReferences);
39+
_restorer.Restore(projectFileInfo, packageSources: Array.Empty<string>());
40+
var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json");
4141
var dependencyContext = _scriptDependencyContextReader.ReadDependencyContext(pathToAssetsFile);
4242
var result = new List<CompilationDependency>();
4343
foreach (var scriptDependency in dependencyContext.Dependencies)
@@ -51,7 +51,7 @@ public IEnumerable<CompilationDependency> GetDependencies(string targetDirectory
5151
private static IRestorer CreateRestorer(LogFactory logFactory)
5252
{
5353
var commandRunner = new CommandRunner(logFactory);
54-
return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory),logFactory);
54+
return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory);
5555
}
5656
}
5757
}

‎src/Dotnet.Script.DependencyModel/Context/CachedRestorer.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Context/CachedRestorer.cs
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ public CachedRestorer(IRestorer restorer, LogFactory logFactory)
2828
public bool CanRestore => _restorer.CanRestore;
2929

3030
/// <inheritdoc/>
31-
public void Restore(string pathToProjectFile, string[] packageSources)
31+
public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources)
3232
{
33-
var projectFile = new ProjectFile(File.ReadAllText(pathToProjectFile));
34-
var pathToCachedProjectFile = $"{pathToProjectFile}.cache";
33+
var projectFile = new ProjectFile(File.ReadAllText(projectFileInfo.Path));
34+
var pathToCachedProjectFile = $"{projectFileInfo.Path}.cache";
3535
if (File.Exists(pathToCachedProjectFile))
3636
{
3737
_logger.Debug($"Found cached csproj file at: {pathToCachedProjectFile}");
3838
var cachedProjectFile = new ProjectFile(File.ReadAllText(pathToCachedProjectFile));
3939
if (projectFile.Equals(cachedProjectFile))
4040
{
41-
_logger.Debug($"Skipping restore. {pathToProjectFile} and {pathToCachedProjectFile} are identical.");
41+
_logger.Debug($"Skipping restore. {projectFileInfo.Path} and {pathToCachedProjectFile} are identical.");
4242
return;
4343
}
4444
else
@@ -55,15 +55,15 @@ public void Restore(string pathToProjectFile, string[] packageSources)
5555

5656
void RestoreAndCacheProjectFile()
5757
{
58-
_restorer.Restore(pathToProjectFile, packageSources);
58+
_restorer.Restore(projectFileInfo, packageSources);
5959
if (projectFile.IsCacheable)
6060
{
6161
_logger.Debug($"Caching project file : {pathToCachedProjectFile}");
6262
projectFile.Save(pathToCachedProjectFile);
6363
}
6464
else
6565
{
66-
_logger.Warning($"Unable to cache {pathToProjectFile}. For caching and optimal performance, ensure that the script(s) references Nuget packages with a pinned version.");
66+
_logger.Warning($"Unable to cache {projectFileInfo.Path}. For caching and optimal performance, ensure that the script(s) references Nuget packages with a pinned version.");
6767
}
6868
}
6969
}

‎src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Dotnet.Script.DependencyModel.Environment;
22
using Dotnet.Script.DependencyModel.Logging;
33
using Dotnet.Script.DependencyModel.Process;
4+
using Dotnet.Script.DependencyModel.ProjectSystem;
45
using System;
56
using System.Linq;
67

@@ -19,18 +20,18 @@ public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory)
1920
_scriptEnvironment = ScriptEnvironment.Default;
2021
}
2122

22-
public void Restore(string pathToProjectFile, string[] packageSources)
23+
public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources)
2324
{
2425
var packageSourcesArgument = CreatePackageSourcesArguments();
2526
var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier;
2627

27-
_logger.Debug($"Restoring {pathToProjectFile} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}");
28-
var exitcode = _commandRunner.Execute("dotnet", $"restore \"{pathToProjectFile}\" -r {runtimeIdentifier} {packageSourcesArgument}");
28+
_logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}");
29+
var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument}");
2930
//var exitcode = _commandRunner.Execute("dotnet", $"restore \"{pathToProjectFile}\" {packageSourcesArgument}");
3031
if (exitcode != 0)
3132
{
3233
// We must throw here, otherwise we may incorrectly run with the old 'project.assets.json'
33-
throw new Exception($"Unable to restore packages from '{pathToProjectFile}'. Make sure that all script files contains valid NuGet references");
34+
throw new Exception($"Unable to restore packages from '{projectFileInfo.Path}'. Make sure that all script files contains valid NuGet references");
3435
}
3536

3637
string CreatePackageSourcesArguments()

‎src/Dotnet.Script.DependencyModel/Context/IRestorer.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Context/IRestorer.cs
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Dotnet.Script.DependencyModel.Context
1+
using Dotnet.Script.DependencyModel.ProjectSystem;
2+
3+
namespace Dotnet.Script.DependencyModel.Context
24
{
35
/// <summary>
46
/// Represents a class that is capable of restoring a project file.
@@ -10,7 +12,8 @@ public interface IRestorer
1012
/// </summary>
1113
/// <param name="pathToProjectFile"></param>
1214
/// <param name="packageSources">A list of packages sources to be used when restoring NuGet packages.</param>
13-
void Restore(string pathToProjectFile, string[] packageSources);
15+
/// <param name="configPath">The path to the NuGet config file to be used when restoring.</param>
16+
void Restore(ProjectFileInfo projectFileInfo, string[] packageSources);
1417

1518
/// <summary>
1619
/// Gets a <see cref="bool"/> value that indicates if this <see cref="IRestorer"/> is available on the system.

‎src/Dotnet.Script.DependencyModel/Context/ProfiledRestorer.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Context/ProfiledRestorer.cs
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using Dotnet.Script.DependencyModel.Logging;
3+
using Dotnet.Script.DependencyModel.ProjectSystem;
34

45
namespace Dotnet.Script.DependencyModel.Context
56
{
@@ -16,11 +17,11 @@ public ProfiledRestorer(IRestorer restorer, LogFactory logFactory)
1617

1718
public bool CanRestore => _restorer.CanRestore;
1819

19-
public void Restore(string pathToProjectFile, string[] packageSources)
20+
public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources)
2021
{
2122
var stopwatch = Stopwatch.StartNew();
22-
_restorer.Restore(pathToProjectFile, packageSources);
23-
_logger.Debug($"Restoring {pathToProjectFile} took {stopwatch.ElapsedMilliseconds}ms");
23+
_restorer.Restore(projectFileInfo, packageSources);
24+
_logger.Debug($"Restoring {projectFileInfo.Path} took {stopwatch.ElapsedMilliseconds}ms");
2425
}
2526
}
2627
}

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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ namespace Dotnet.Script.DependencyModel.ProjectSystem
66
{
77
internal static class NuGetUtilities
88
{
9+
10+
public static string GetNearestConfigPath(string pathToEvaluate)
11+
{
12+
var settings = Settings.LoadDefaultSettings(pathToEvaluate);
13+
return settings.GetConfigFilePaths().FirstOrDefault();
14+
}
15+
916
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
1017
{
1118
var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate);

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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs
+21-7Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private ScriptProjectProvider(ScriptParser scriptParser, ScriptFilesResolver scr
2727
{
2828
}
2929

30-
public string CreateProjectForRepl(string code, string targetDirectory, string defaultTargetFramework = "net46")
30+
public ProjectFileInfo CreateProjectForRepl(string code, string targetDirectory, string defaultTargetFramework = "net46")
3131
{
3232
var scriptFiles = _scriptFilesResolver.GetScriptFilesFromCode(code);
3333
targetDirectory = Path.Combine(targetDirectory, "interactive");
@@ -62,7 +62,9 @@ public string CreateProjectForRepl(string code, string targetDirectory, string d
6262
LogProjectFileInfo(pathToProjectFile);
6363

6464
EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
65-
return pathToProjectFile;
65+
//return ret pathToProjectFile;
66+
67+
return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory));
6668
}
6769

6870
private void LogProjectFileInfo(string pathToProjectFile)
@@ -72,12 +74,12 @@ private void LogProjectFileInfo(string pathToProjectFile)
7274
_logger.Debug(content);
7375
}
7476

75-
public string CreateProject(string targetDirectory, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false)
77+
public ProjectFileInfo CreateProject(string targetDirectory, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false)
7678
{
7779
return CreateProject(targetDirectory, Directory.GetFiles(targetDirectory, "*.csx", SearchOption.AllDirectories), defaultTargetFramework, enableNuGetScriptReferences);
7880
}
7981

80-
public string CreateProject(string targetDirectory, IEnumerable<string> scriptFiles, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false)
82+
public ProjectFileInfo CreateProject(string targetDirectory, IEnumerable<string> scriptFiles, string defaultTargetFramework = "net46", bool enableNuGetScriptReferences = false)
8183
{
8284
if (scriptFiles == null || !scriptFiles.Any())
8385
{
@@ -95,14 +97,14 @@ public string CreateProject(string targetDirectory, IEnumerable<string> scriptFi
9597
return SaveProjectFileFromScriptFiles(targetDirectory, defaultTargetFramework, scriptFiles.ToArray());
9698
}
9799

98-
public string CreateProjectForScriptFile(string scriptFile)
100+
public ProjectFileInfo CreateProjectForScriptFile(string scriptFile)
99101
{
100102
_logger.Debug($"Creating project file for {scriptFile}");
101103
var scriptFiles = _scriptFilesResolver.GetScriptFiles(scriptFile);
102104
return SaveProjectFileFromScriptFiles(Path.GetDirectoryName(scriptFile), _scriptEnvironment.TargetFramework, scriptFiles.ToArray());
103105
}
104106

105-
private string SaveProjectFileFromScriptFiles(string targetDirectory, string defaultTargetFramework, string[] csxFiles)
107+
private ProjectFileInfo SaveProjectFileFromScriptFiles(string targetDirectory, string defaultTargetFramework, string[] csxFiles)
106108
{
107109
ProjectFile projectFile = CreateProjectFileFromScriptFiles(defaultTargetFramework, csxFiles);
108110

@@ -112,7 +114,7 @@ private string SaveProjectFileFromScriptFiles(string targetDirectory, string def
112114
LogProjectFileInfo(pathToProjectFile);
113115

114116
EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
115-
return pathToProjectFile;
117+
return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory));
116118
}
117119

118120
public ProjectFile CreateProjectFileFromScriptFiles(string defaultTargetFramework, string[] csxFiles)
@@ -148,4 +150,16 @@ public static string GetPathToProjectFile(string targetDirectory)
148150
return pathToProjectFile;
149151
}
150152
}
153+
154+
public class ProjectFileInfo
155+
{
156+
public ProjectFileInfo(string path, string configPath)
157+
{
158+
Path = path;
159+
ConfigPath = configPath;
160+
}
161+
162+
public string Path { get; }
163+
public string ConfigPath { get; }
164+
}
151165
}

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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@ public RuntimeDependencyResolver(ScriptProjectProvider scriptProjectProvider, Lo
2727
_restorer = CreateRestorer(logFactory, useRestoreCache);
2828
}
2929

30-
public RuntimeDependencyResolver(LogFactory logFactory, bool useRestoreCache) : this(new ScriptProjectProvider(logFactory), logFactory, ScriptEnvironment.Default, useRestoreCache)
31-
{
30+
public RuntimeDependencyResolver(LogFactory logFactory, bool useRestoreCache) : this(new ScriptProjectProvider(logFactory), logFactory, ScriptEnvironment.Default, useRestoreCache)
31+
{
3232

33-
}
33+
}
3434

3535
private static IRestorer CreateRestorer(LogFactory logFactory, bool useRestoreCache)
3636
{
3737
var commandRunner = new CommandRunner(logFactory);
3838
if (useRestoreCache)
3939
{
40-
return new ProfiledRestorer(new CachedRestorer(new DotnetRestorer(commandRunner, logFactory),logFactory),logFactory);
40+
return new ProfiledRestorer(new CachedRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory), logFactory);
4141
}
4242
else
4343
{
44-
return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory),logFactory);
44+
return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory);
4545
}
4646
}
4747

4848
public IEnumerable<RuntimeDependency> GetDependencies(string scriptFile, string[] packageSources)
4949
{
50-
var pathToProjectFile = _scriptProjectProvider.CreateProjectForScriptFile(scriptFile);
51-
_restorer.Restore(pathToProjectFile, packageSources);
52-
var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json");
50+
var projectFileInfo = _scriptProjectProvider.CreateProjectForScriptFile(scriptFile);
51+
_restorer.Restore(projectFileInfo, packageSources);
52+
var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json");
5353
return GetDependenciesInternal(pathToAssetsFile);
5454
}
5555

@@ -61,9 +61,9 @@ public IEnumerable<RuntimeDependency> GetDependenciesForLibrary(string pathToLib
6161

6262
public IEnumerable<RuntimeDependency> GetDependenciesForCode(string targetDirectory, ScriptMode scriptMode, string[] packageSources, string code = null)
6363
{
64-
var pathToProjectFile = _scriptProjectProvider.CreateProjectForRepl(code, Path.Combine(targetDirectory, scriptMode.ToString()), ScriptEnvironment.Default.TargetFramework);
65-
_restorer.Restore(pathToProjectFile, packageSources);
66-
var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json");
64+
var projectFileInfo = _scriptProjectProvider.CreateProjectForRepl(code, Path.Combine(targetDirectory, scriptMode.ToString()), ScriptEnvironment.Default.TargetFramework);
65+
_restorer.Restore(projectFileInfo, packageSources);
66+
var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json");
6767
return GetDependenciesInternal(pathToAssetsFile);
6868
}
6969

@@ -74,7 +74,7 @@ private IEnumerable<RuntimeDependency> GetDependenciesInternal(string pathToAsse
7474
foreach (var scriptDependency in context.Dependencies)
7575
{
7676
var runtimeAssemblies = scriptDependency.RuntimeDependencyPaths.Select(rdp => new RuntimeAssembly(AssemblyName.GetAssemblyName(rdp), rdp)).ToList();
77-
var runtimeDependency = new RuntimeDependency(scriptDependency.Name, scriptDependency.Version,runtimeAssemblies, scriptDependency.NativeAssetPaths,scriptDependency.ScriptPaths);
77+
var runtimeDependency = new RuntimeDependency(scriptDependency.Name, scriptDependency.Version, runtimeAssemblies, scriptDependency.NativeAssetPaths, scriptDependency.ScriptPaths);
7878
result.Add(runtimeDependency);
7979
}
8080

0 commit comments

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