Skip to content

Commit

Permalink
Release v4.1.2.0-pre:
Browse files Browse the repository at this point in the history
- Issue #253: Supports both .Net Framework and .Net 5
  • Loading branch information
oleg.shilo authored and oleg.shilo committed Sep 12, 2021
1 parent dcbf116 commit 6755bb3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/CSScriptLib/src/CSScriptLib/CSScriptLib.csproj
Expand Up @@ -13,7 +13,7 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>4.1.1.0-pre</Version>
<Version>4.1.2.0-pre</Version>
<Authors>Oleg Shilo</Authors>
<Description>CS-Script engine Class Library for .NET 5</Description>
<Copyright>(C) 2018-2021 Oleg Shilo</Copyright>
Expand All @@ -29,8 +29,8 @@

</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<FileVersion>4.1.1.0</FileVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<FileVersion>4.1.2.0</FileVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>css_logo.png</PackageIcon>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CSScriptLib/src/CSScriptLib/Evaluator.CodeDom.cs
Expand Up @@ -155,7 +155,7 @@ override protected (byte[] asm, byte[] pdb) Compile(string scriptText, string sc
{
string projectName = fileNames.First().GetFileName();

var engine_dir = this.GetType().Assembly.Location.GetDirName();
var engine_dir = this.GetType().Assembly.Location().GetDirName();
var cache_dir = CSExecutor.ScriptCacheDir; // C:\Users\user\AppData\Local\Temp\csscript.core\cache\1822444284
var build_dir = cache_dir.PathJoin(".build", projectName);

Expand Down
2 changes: 1 addition & 1 deletion src/CSScriptLib/src/CSScriptLib/Evaluator.Roslyn.cs
Expand Up @@ -302,7 +302,7 @@ override protected (byte[] asm, byte[] pdb) Compile(string scriptText, string sc

if (!DisableReferencingFromCode)
{
var localDir = Path.GetDirectoryName(this.GetType().Assembly.Location);
var localDir = this.GetType().Assembly.Location().GetDirName();
ReferenceAssembliesFromCode(scriptText, localDir);
}

Expand Down
8 changes: 6 additions & 2 deletions src/cscs/Utils/PathExtensions.cs
Expand Up @@ -197,15 +197,19 @@ void del_dir(string d)
/// </summary>
/// <param name="path">The path.</param>
/// <returns>The result of the test.</returns>
public static bool FileExists(this string path) => path.IsNotEmpty() ? File.Exists(path) : false;
public static bool FileExists(this string path)
{
try { return path.IsNotEmpty() ? File.Exists(path) : false; }
catch { return false; }
}

/// <summary>
/// Gets the directory name from the path.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>The directory path.</returns>
public static string GetDirName(this string path)
=> path == null ? null : Path.GetDirectoryName(path);
=> path == null ? null : Path.GetDirectoryName(path);

/// <summary>
/// Changes the name of the file.
Expand Down
21 changes: 13 additions & 8 deletions src/cscs/Utils/ReflectionExtensions.cs
Expand Up @@ -147,13 +147,18 @@ public static string Location(this Assembly asm)
string location = Environment.GetEnvironmentVariable("location:" + asm.GetHashCode());
if (location == null)
{
var validPath = asm.CodeBase?.FromUriToPath();

if (validPath.FileExists())
return validPath;

// Note assembly can contain only single AssemblyDescriptionAttribute
return asm.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), true)?
.Cast<AssemblyDescriptionAttribute>()
.FirstOrDefault()?
.Description
??
"";
.Cast<AssemblyDescriptionAttribute>()
.FirstOrDefault()?
.Description
??
"";
}
else
return location ?? "";
Expand All @@ -162,6 +167,9 @@ public static string Location(this Assembly asm)
return asm.Location;
}

internal static string FromUriToPath(this string uri)
=> new Uri(uri).LocalPath;

/// <summary>
/// Gets the name of the type.
/// </summary>
Expand Down Expand Up @@ -243,10 +251,7 @@ internal static IEnumerable<Type> OrderedUserTypes(this Assembly asm)

internal static Type FirstUserTypeAssignableFrom<T>(this Assembly asm)
=> asm.OrderedUserTypes().FirstOrDefault(x => typeof(T).IsAssignableFrom(x));
}

public static class ReflectionExtensions_FX
{
/// <summary>
/// Determines whether the assembly is dynamic.
/// </summary>
Expand Down

0 comments on commit 6755bb3

Please sign in to comment.