【发布时间】:2018-06-26 17:58:59
【问题描述】:
我需要在构建后从我的一些 C# 类生成 typescript 文件。
我创建了dotnet cli tool 并添加了构建后事件
dotnet tsgenerator "$(TargetPath)"
其中$(TargetPath) 是指向的宏,例如D:\Test\bin\Release\netcoreapp2.0\my.dll
接下来,我尝试加载程序集:
public static void Main(string[] args)
{
var dllPath = args[0]; // "D:\Test\bin\Release\netcoreapp2.0\my.dll"
var assembly = Assembly.LoadFile(dllPath);
var types = assembly.GetExportedTypes(); // Throws exception
}
但是对于某些引用程序集(例如,Microsoft.AspNetCore.Antiforgery),我得到了 ReflectionTypeLoadException,上面写着 Could not load file or assembly。
如何为 .NET Core 应用程序加载程序集?
【问题讨论】:
-
什么是
dllPath? -
@DanielA.White 来自 MSBuild 的参数
$(TargetPath) -
这是怎么设置的?
-
@DanielA.White 项目设置 -> 构建事件 -> 构建后事件:
dotnet tsgenerator "$(TargetPath)" -
在c#中......
标签: c# .net asp.net-core .net-core