oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.56k stars 234 forks source link

Location of script file Unable to get correct results in hosted script #371

Closed int2e closed 2 months ago

int2e commented 2 months ago

https://github.com/oleg-shilo/cs-script/wiki/CS-Script-Runtime-Environment-%28script-reflection%29

using System.Linq;
using System.Reflection;

public static class StringExtensions
{
    public static string GetScriptName(this Assembly assembly)
    {
        return assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)
            .Cast<AssemblyDescriptionAttribute>()
            .FirstOrDefault()?.Description;
    }
}

var scriptName = Assembly.GetExecutingAssembly().GetScriptName();

scriptName is null

Does it only work in cli?

oleg-shilo commented 2 months ago

You are correct. After porting the codebase to .NET Core the usage of AssemblyDescriptionAttribute has changed and it holds now the location of the assembly file but not its source. This defect breaks this functionality. And on top of it the documentation was not changed to reflect that.

I have reviewed the code and believe that the decision for repurposing AssemblyDescriptionAttribute was not the best.

I am requalifying this issue as a defect and going to fix it. I will publish the HotFix release very soon.

oleg-shilo commented 2 months ago

I just have published the pre-release of the fix on nuget.org

dotnet add package CS-Script --version 4.8.16-pre
int2e commented 2 months ago

I just have published the pre-release of the fix on nuget.org我刚刚发布了修复程序的预发布 nuget.org

dotnet add package CS-Script --version 4.8.16-pre

4.8.16-pre can obtain the path!

thanks!