簡體   English   中英

Fody 和 Assembly.GetExecutingAssembly().Location 返回空字符串

[英]Fody and Assembly.GetExecutingAssembly().Location returns empty string

我在我的解決方案的一個 dll 中調用了Assembly.GetExecutingAssembly().Location 當我嘗試使用 Fody ( https://www.nuget.org/packages/Fody/ ) 到 package 時,注意到執行調用程序集的二進制文件的空字符串開始返回這個二進制文件的空字符串。 這應該被認為是一個錯誤嗎? 使用 Fody 時有沒有辦法獲取這些信息? 如果我從解決方案的主項目進行調用,它似乎工作正常。

這是我的主要方法:

static void Main(string[] args)
{
    Console.WriteLine($"From Main: \"{Assembly.GetExecutingAssembly().Location}\"");
    Console.WriteLine($"From dll:  \"{Class1.GetLocation()}\"");
}

然后GetLocation方法在 dll 中定義,如下所示:

public static string GetLocation()
{
    return Assembly.GetExecutingAssembly().Location;
}

沒有 Fody 的控制台中的 output 看起來像這樣:

From Main: "C:\Prog\ConsoleApp1\bin\Debug\ConsoleApp1.exe"
From dll:  "C:\Prog\ConsoleApp1\bin\Debug\ClassLibrary1.dll"

添加 Fody 后,它看起來像這樣:

From Main: "C:\Prog\ConsoleApp1\bin\Debug\ConsoleApp1.exe"
From dll:  ""

使用Costura ,默認情況下程序集從 memory 加載,因此沒有位置。

要更改此設置,您可以在FodyWeavers.xml中設置CreateTemporaryAssemblies ,這將在加載程序集之前將它們保存到臨時位置。

<Costura CreateTemporaryAssemblies='true' />

試試這個AppDomain.CurrentDomain.BaseDirectory

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM