Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<TReturn> Execute<TReturn>(ExecuteCodeCommandOptions options)
{
var sourceText = SourceText.From(options.Code);
var context = new ScriptContext(sourceText, options.WorkingDirectory ?? Directory.GetCurrentDirectory(), options.Arguments, null, options.OptimizationLevel, ScriptMode.Eval, options.PackageSources);
var compiler = new ScriptCompiler(_logFactory, !options.NoCache)
var compiler = new ScriptCompiler(_logFactory, options.CachePath, !options.NoCache)
{
#if NETCOREAPP
AssemblyLoadContext = options.AssemblyLoadContext
Expand Down
4 changes: 3 additions & 1 deletion src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ namespace Dotnet.Script.Core.Commands
{
public class ExecuteCodeCommandOptions
{
public ExecuteCodeCommandOptions(string code, string workingDirectory, string[] arguments, OptimizationLevel optimizationLevel, bool noCache, string[] packageSources)
public ExecuteCodeCommandOptions(string code, string workingDirectory, string[] arguments, OptimizationLevel optimizationLevel, string cachePath, bool noCache, string[] packageSources)
{
Code = code;
WorkingDirectory = workingDirectory;
Arguments = arguments;
OptimizationLevel = optimizationLevel;
CachePath = cachePath;
NoCache = noCache;
PackageSources = packageSources;
}
Expand All @@ -21,6 +22,7 @@ public ExecuteCodeCommandOptions(string code, string workingDirectory, string[]
public string WorkingDirectory { get; }
public string[] Arguments { get; }
public OptimizationLevel OptimizationLevel { get; }
public string CachePath { get; }
public bool NoCache { get; }
public string[] PackageSources { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ExecuteInteractiveCommand(ScriptConsole scriptConsole, LogFactory logFact

public async Task<int> Execute(ExecuteInteractiveCommandOptions options)
{
var compiler = new ScriptCompiler(_logFactory, useRestoreCache: false)
var compiler = new ScriptCompiler(_logFactory, options.CachePath, useRestoreCache: false)
{
#if NETCOREAPP
AssemblyLoadContext = options.AssemblyLoadContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ namespace Dotnet.Script.Core.Commands
{
public class ExecuteInteractiveCommandOptions
{
public ExecuteInteractiveCommandOptions(ScriptFile scriptFile, string[] arguments, string[] packageSources)
public ExecuteInteractiveCommandOptions(ScriptFile scriptFile, string[] arguments, string[] packageSources, string cachePath)
{
ScriptFile = scriptFile;
Arguments = arguments;
PackageSources = packageSources;
CachePath = cachePath;
}

public ScriptFile ScriptFile { get; }
public string[] Arguments { get; }
public string[] PackageSources { get; }
public string CachePath { get; }

#if NETCOREAPP
#nullable enable
Expand Down
2 changes: 1 addition & 1 deletion src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<TReturn> Execute<TReturn>(ExecuteLibraryCommandOptions options
}

var absoluteFilePath = options.LibraryPath.GetRootedPath();
var compiler = new ScriptCompiler(_logFactory, !options.NoCache)
var compiler = new ScriptCompiler(_logFactory, options.CachePath, !options.NoCache)
{
#if NETCOREAPP
AssemblyLoadContext = options.AssemblyLoadContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ namespace Dotnet.Script.Core.Commands
{
public class ExecuteLibraryCommandOptions
{
public ExecuteLibraryCommandOptions(string libraryPath, string[] arguments, bool noCache)
public ExecuteLibraryCommandOptions(string libraryPath, string[] arguments, string cachePath, bool noCache)
{
LibraryPath = libraryPath;
Arguments = arguments;
CachePath = cachePath;
NoCache = noCache;
}

public string LibraryPath { get; }
public string[] Arguments { get; }
public string CachePath { get; }
public bool NoCache { get; }

#if NETCOREAPP
Expand Down
10 changes: 5 additions & 5 deletions src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<TReturn> Run<TReturn, THost>(ExecuteScriptCommandOptions optio

var pathToLibrary = GetLibrary<TReturn>(options);

var libraryOptions = new ExecuteLibraryCommandOptions(pathToLibrary, options.Arguments, options.NoCache)
var libraryOptions = new ExecuteLibraryCommandOptions(pathToLibrary, options.Arguments, options.CachePath, options.NoCache)
{
#if NETCOREAPP
AssemblyLoadContext = options.AssemblyLoadContext
Expand All @@ -46,13 +46,13 @@ private async Task<TReturn> DownloadAndRunCode<TReturn>(ExecuteScriptCommandOpti
{
var downloader = new ScriptDownloader();
var code = await downloader.Download(executeOptions.File.Path);
var options = new ExecuteCodeCommandOptions(code, Directory.GetCurrentDirectory(), executeOptions.Arguments, executeOptions.OptimizationLevel, executeOptions.NoCache, executeOptions.PackageSources);
var options = new ExecuteCodeCommandOptions(code, Directory.GetCurrentDirectory(), executeOptions.Arguments, executeOptions.OptimizationLevel, executeOptions.CachePath, executeOptions.NoCache, executeOptions.PackageSources);
return await new ExecuteCodeCommand(_scriptConsole, _logFactory).Execute<TReturn>(options);
}

private string GetLibrary<TReturn>(ExecuteScriptCommandOptions executeOptions)
{
var projectFolder = FileUtils.GetPathToScriptTempFolder(executeOptions.File.Path);
var projectFolder = FileUtils.GetPathToScriptTempFolder(executeOptions.File.Path, executeOptions.CachePath);
var executionCacheFolder = Path.Combine(projectFolder, "execution-cache");
var pathToLibrary = Path.Combine(executionCacheFolder, "script.dll");

Expand All @@ -64,7 +64,7 @@ private string GetLibrary<TReturn>(ExecuteScriptCommandOptions executeOptions)
return pathToLibrary;
}

var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache)
var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.CachePath, executeOptions.NoCache)
{
#if NETCOREAPP
AssemblyLoadContext = executeOptions.AssemblyLoadContext
Expand All @@ -89,7 +89,7 @@ public bool TryCreateHash(ExecuteScriptCommandOptions options, out string hash)

var scriptFilesProvider = new ScriptFilesResolver();
var allScriptFiles = scriptFilesProvider.GetScriptFiles(options.File.Path);
var projectFile = new ScriptProjectProvider(_logFactory).CreateProjectFileFromScriptFiles(ScriptEnvironment.Default.TargetFramework, allScriptFiles.ToArray());
var projectFile = new ScriptProjectProvider(_logFactory, options.CachePath).CreateProjectFileFromScriptFiles(ScriptEnvironment.Default.TargetFramework, allScriptFiles.ToArray());

if (!projectFile.IsCacheable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ namespace Dotnet.Script.Core.Commands
{
public class ExecuteScriptCommandOptions
{
public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, OptimizationLevel optimizationLevel, string[] packageSources, bool isInteractive ,bool noCache)
public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, OptimizationLevel optimizationLevel, string[] packageSources, bool isInteractive, string cachePath, bool noCache)
{
File = file;
Arguments = arguments;
OptimizationLevel = optimizationLevel;
PackageSources = packageSources;
IsInteractive = isInteractive;
CachePath = cachePath;
NoCache = noCache;
}

Expand All @@ -22,6 +23,7 @@ public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, Optimiza
public OptimizationLevel OptimizationLevel { get; }
public string[] PackageSources { get; }
public bool IsInteractive { get; }
public string CachePath { get; }
public bool NoCache { get; }

#if NETCOREAPP
Expand Down
4 changes: 2 additions & 2 deletions src/Dotnet.Script.Core/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public void Execute<TReturn>(PublishCommandOptions options)
(options.PublishType == PublishType.Library ? Path.Combine(Path.GetDirectoryName(absoluteFilePath), "publish") : Path.Combine(Path.GetDirectoryName(absoluteFilePath), "publish", options.RuntimeIdentifier));

var absolutePublishDirectory = publishDirectory.GetRootedPath();
var compiler = new ScriptCompiler(_logFactory, !options.NoCache)
var compiler = new ScriptCompiler(_logFactory, options.CachePath, !options.NoCache)
{
#if NETCOREAPP
AssemblyLoadContext = options.AssemblyLoadContext
#endif
};
var scriptEmitter = new ScriptEmitter(_scriptConsole, compiler);
var publisher = new ScriptPublisher(_logFactory, scriptEmitter);
var publisher = new ScriptPublisher(_logFactory, scriptEmitter, options.CachePath);
var code = absoluteFilePath.ToSourceText();
var context = new ScriptContext(code, absolutePublishDirectory, Enumerable.Empty<string>(), absoluteFilePath, options.OptimizationLevel, packageSources: options.PackageSources);

Expand Down
4 changes: 3 additions & 1 deletion src/Dotnet.Script.Core/Commands/PublishCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dotnet.Script.Core.Commands
{
public class PublishCommandOptions
{
public PublishCommandOptions(ScriptFile file, string outputDirectory, string libraryName, PublishType publishType, OptimizationLevel optimizationLevel, string[] packageSources, string runtimeIdentifier, bool noCache)
public PublishCommandOptions(ScriptFile file, string outputDirectory, string libraryName, PublishType publishType, OptimizationLevel optimizationLevel, string[] packageSources, string runtimeIdentifier, string cachePath, bool noCache)
{
File = file;
OutputDirectory = outputDirectory;
Expand All @@ -17,6 +17,7 @@ public PublishCommandOptions(ScriptFile file, string outputDirectory, string lib
OptimizationLevel = optimizationLevel;
PackageSources = packageSources;
RuntimeIdentifier = runtimeIdentifier ?? ScriptEnvironment.Default.RuntimeIdentifier;
CachePath = cachePath;
NoCache = noCache;
}

Expand All @@ -27,6 +28,7 @@ public PublishCommandOptions(ScriptFile file, string outputDirectory, string lib
public OptimizationLevel OptimizationLevel { get; }
public string[] PackageSources { get; }
public string RuntimeIdentifier { get; }
public string CachePath { get; }
public bool NoCache { get; }

#if NETCOREAPP
Expand Down
2 changes: 1 addition & 1 deletion src/Dotnet.Script.Core/Dotnet.Script.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn.</Description>
<VersionPrefix>1.6.0</VersionPrefix>
Copy link
Member

@filipw filipw Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rev all of these up to 1.7.0?

<VersionPrefix>1.7.0</VersionPrefix>
<Authors>filipw</Authors>
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>
<AssemblyName>Dotnet.Script.Core</AssemblyName>
Expand Down
4 changes: 2 additions & 2 deletions src/Dotnet.Script.Core/ScriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ static ScriptCompiler()

public RuntimeDependencyResolver RuntimeDependencyResolver { get; }

public ScriptCompiler(LogFactory logFactory, bool useRestoreCache)
: this(logFactory, new RuntimeDependencyResolver(logFactory, useRestoreCache))
public ScriptCompiler(LogFactory logFactory, string cachePath, bool useRestoreCache)
: this(logFactory, new RuntimeDependencyResolver(logFactory, cachePath, useRestoreCache))
{

}
Expand Down
12 changes: 6 additions & 6 deletions src/Dotnet.Script.Core/ScriptPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public ScriptPublisher(ScriptProjectProvider scriptProjectProvider, ScriptEmitte
_scriptEnvironment = ScriptEnvironment.Default;
}

public ScriptPublisher(LogFactory logFactory, ScriptEmitter scriptEmitter)
public ScriptPublisher(LogFactory logFactory, ScriptEmitter scriptEmitter, string cachePath)
: this
(
new ScriptProjectProvider(logFactory),
new ScriptProjectProvider(logFactory, cachePath),
scriptEmitter,
ScriptConsole.Default
)
Expand All @@ -43,7 +43,7 @@ public void CreateAssembly<TReturn, THost>(ScriptContext context, LogFactory log

assemblyFileName = assemblyFileName ?? Path.GetFileNameWithoutExtension(context.FilePath);
var scriptAssemblyPath = CreateScriptAssembly<TReturn, THost>(context, context.WorkingDirectory, assemblyFileName);
var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), ScriptEnvironment.Default.TargetFramework);
var tempProjectPath = _scriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), ScriptEnvironment.Default.TargetFramework);
var tempProjectDirecory = Path.GetDirectoryName(tempProjectPath);

var sourceProjectAssetsPath = Path.Combine(tempProjectDirecory, "obj", "project.assets.json");
Expand All @@ -55,7 +55,7 @@ public void CreateAssembly<TReturn, THost>(ScriptContext context, LogFactory log
File.Copy(sourceNugetPropsPath, destinationNugetPropsPath, overwrite: true);

// only display published if we aren't auto publishing to temp folder
if (!scriptAssemblyPath.StartsWith(FileUtils.GetTempPath()))
if (!_scriptProjectProvider.IsTempPath(scriptAssemblyPath))
{
_scriptConsole.WriteSuccess($"Published {context.FilePath} to {scriptAssemblyPath}");
}
Expand All @@ -71,8 +71,8 @@ public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory l
executableFileName ??= Path.GetFileNameWithoutExtension(context.FilePath);
const string AssemblyName = "scriptAssembly";

var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework);
var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework, executableFileName);
var tempProjectPath = _scriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework);
var renamedProjectPath = _scriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework, executableFileName);
var tempProjectDirectory = Path.GetDirectoryName(tempProjectPath);

var scriptAssemblyPath = CreateScriptAssembly<TReturn, THost>(context, tempProjectDirectory, AssemblyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RepositoryUrl>https://github.com/dotnet-script/dotnet-script.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>script;csx;csharp;roslyn;nuget</PackageTags>
<Version>1.6.0</Version>
<Version>1.7.0</Version>
<Description>A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files.</Description>
<Authors>dotnet-script</Authors>
<Company>dotnet-script</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CompilationDependencyResolver

private readonly IRestorer _restorer;

public CompilationDependencyResolver(LogFactory logFactory) : this(new ScriptProjectProvider(logFactory), new ScriptDependencyContextReader(logFactory), new CompilationReferencesReader(logFactory), logFactory)
public CompilationDependencyResolver(LogFactory logFactory, string cachePath) : this(new ScriptProjectProvider(logFactory, cachePath), new ScriptDependencyContextReader(logFactory), new CompilationReferencesReader(logFactory), logFactory)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/dotnet-script/dotnet-script.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>script;csx;csharp;roslyn;omnisharp</PackageTags>
<Version>1.6.0</Version>
<Version>1.7.0</Version>
<LangVersion>latest</LangVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../dotnet-script.snk</AssemblyOriginatorKeyFile>
Expand Down
12 changes: 8 additions & 4 deletions src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Dotnet.Script.DependencyModel.ProjectSystem
{
public static class FileUtils
{
public static string CreateTempFolder(string targetDirectory, string targetFramework)
public static string CreateTempFolder(string targetDirectory, string cachePath, string targetFramework)
{
string pathToProjectDirectory = Path.Combine(GetPathToScriptTempFolder(targetDirectory), targetFramework);
string pathToProjectDirectory = Path.Combine(GetPathToScriptTempFolder(targetDirectory, cachePath), targetFramework);

if (!Directory.Exists(pathToProjectDirectory))
{
Expand All @@ -22,14 +22,18 @@ public static string CreateTempFolder(string targetDirectory, string targetFrame
return pathToProjectDirectory;
}

public static string GetPathToScriptTempFolder(string targetDirectory)
public static string GetPathToScriptTempFolder(string targetDirectory, string cachePath)
{
if (!Path.IsPathRooted(targetDirectory))
{
throw new ArgumentOutOfRangeException(nameof(targetDirectory), "Must be a root path");
}

var tempDirectory = GetTempPath();
var tempDirectory =
string.IsNullOrEmpty(cachePath) ? GetTempPath() :
Path.IsPathRooted(cachePath) ? cachePath :
Path.Combine(Directory.GetCurrentDirectory(), cachePath);

var pathRoot = Path.GetPathRoot(targetDirectory);
var targetDirectoryWithoutRoot = targetDirectory.Substring(pathRoot.Length);
if (pathRoot.Length > 0 && ScriptEnvironment.Default.IsWindows)
Expand Down
Loading
Loading