Skip to content

Commit

Permalink
CLI
Browse files Browse the repository at this point in the history
- Invoking `SetScriptReflection` (SetEnvironmentVariable("location:" ...) is now disabled by default. It cna be enabled by setting environment variable CSS_SCRIPTLOCATIONREFLECTION to non empty string.

- Some usability improvements around NuGet support (triggered by #364)
  • Loading branch information
oleg-shilo committed Feb 8, 2024
1 parent a368d5b commit 4a51b23
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion help.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
C# Script execution engine (.NET Core). Version 4.8.13.0.
C# Script execution engine (.NET Core). Version 4.8.14.1.
Copyright (C) 2004-2023 Oleg Shilo.


Expand Down
4 changes: 3 additions & 1 deletion src/cscs/AssemblyExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ void ExecuteLoadedAssembly(string filename, string[] args, SystemWideLock asmLoc

asmLock?.Release();
}
SetScriptReflection(assembly, Path.GetFullPath(filename), true);


SetScriptReflection(assembly, Path.GetFullPath(filename), "CSS_SCRIPTLOCATIONREFLECTION".GetEnvar().HasText());
InvokeStaticMain(assembly, args);
}
catch (FileLoadException e)
Expand Down
4 changes: 2 additions & 2 deletions src/cscs/HelpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,8 @@ static AppArgs()
"Even when the script loaded in-memory (InMemoryAssembly setting) but not from the original file. " +
"(e.g. var location = Environment.GetEnvironmentVariable(\"location:\" + Assembly.GetExecutingAssembly().GetHashCode()); ",
" ",
"Note that by default setting of 'location:<asm_hash>' is disabled. You can enable it by calling " +
" 'CSScript.EnableScriptLocationReflection = true'.",
"Note that by default setting of 'location:<asm_hash>' is disabled. You can enable it by setting" +
" 'CSS_SCRIPTLOCATIONREFLECTION' environment variable to non empty string.",
" ",
"The following is the optional set of environment variables that the script engine uses to improve the user experience:",
" ",
Expand Down
24 changes: 16 additions & 8 deletions src/cscs/NuGet.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NuGet
static NuGetCore nuget = new NuGetCore();

static public string NuGetCacheView => Directory.Exists(NuGetCache) ? NuGetCache : "<not found>";
static public string NuGetCache => CSExecutor.options.legacyNugetSupport ? NuGetCore.NuGetCache : NuGetDotnet.NuGetCache;
static public string NuGetCache => CSExecutor.options.legacyNugetSupport ? NuGetCore.NuGetCache : NuGetNewAlgorithm.NuGetCache;

static public string NuGetExeView
=> (NuGetCore.NuGetExe.FileExists() || NuGetCore.NuGetExe == "dotnet") ? NuGetCore.NuGetExe : "<not found>";
Expand All @@ -51,7 +51,7 @@ static public void ListPackages()
static public string[] Resolve(string[] packages, bool suppressDownloading, string script)
=> CSExecutor.options.legacyNugetSupport ?
NuGetCore.Resolve(packages, suppressDownloading, script) :
NuGetDotnet.FindAssembliesOf(packages, suppressDownloading, script);
NuGetNewAlgorithm.FindAssembliesOf(packages, suppressDownloading, script);
}

class NuGetCore
Expand Down Expand Up @@ -126,8 +126,12 @@ static public void InstallPackage(string packageNameMask, string version = null,
{
Task.Run(() =>
{
nuget_dir.DeleteDir();
ClearAnabdonedNugetDirs(nuget_dir.GetDirName());
try
{
nuget_dir.DeleteDir();
ClearAnabdonedNugetDirs(nuget_dir.GetDirName());
}
catch { }
});
}
}
Expand All @@ -139,8 +143,12 @@ static void ClearAnabdonedNugetDirs(string nuget_root)
{
if (int.TryParse(item.GetFileName(), out int proc_id))
{
if (Process.GetProcessById(proc_id) == null)
try { item.DeleteDir(); } catch { }
try
{
if (Process.GetProcessById(proc_id) == null)
item.DeleteDir();
}
catch { }
}
}
}
Expand Down Expand Up @@ -351,7 +359,7 @@ static PackageInfo FindPackage(string name, string version)
.ToArray();

return packages.FirstOrDefault(x => string.Compare(x.Name, name, StringComparison.OrdinalIgnoreCase) == 0 &&
(version.IsEmpty() || version == x.Version));
(version.IsEmpty() || version == "*" || version == x.Version));
}

static public string[] Resolve(string[] packages, bool suppressDownloading, string script)
Expand Down Expand Up @@ -456,7 +464,7 @@ static public string[] Resolve(string[] packages, bool suppressDownloading, stri
}
}

class NuGetDotnet
class NuGetNewAlgorithm
{
static string[] GetPackagesFromConfigFileOfScript(string scriptFile)
{
Expand Down
2 changes: 2 additions & 0 deletions src/cscs/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ public bool ResolveRelativeFromParentScriptLocation

/// <summary>
/// Gets or sets a value indicating whether legacy NuGet support is enabled (default) or disabled.
/// See https://github.com/oleg-shilo/cs-script/wiki/NuGet-Support
/// </summary>
/// <value>
/// <c>true</c> if legacy NuGet support is enabled; otherwise, <c>false</c>.
/// </value>
[Description(@"Gets or sets a value indicating whether legacy NuGet support is enabled (default) or disabled.
See https://github.com/oleg-shilo/cs-script/wiki/NuGet-Support
`true` if legacy NuGet support is enabled; otherwise, `false`.")]
public bool LegacyNugetSupport { get; set; } = true;
Expand Down

0 comments on commit 4a51b23

Please sign in to comment.