小编max*_*her的帖子

访问ASP.NET Core中的当前HttpContext

我需要HttpContext在静态方法或实用程序服务中访问当前.

使用经典的ASP.NET MVC System.Web,我只是用来HttpContext.Current静态访问上下文.但是我如何在ASP.NET Core中执行此操作?

c# asp.net-core

113
推荐指数
6
解决办法
4万
查看次数

PostBuild事件中的.NET Core Assembly.LoadFile

我需要typescript在构建之后从我的一些C#类生成文件.

我创建dotnet cli tool并添加了post-build事件

dotnet tsgenerator "$(TargetPath)"
Run Code Online (Sandbox Code Playgroud)

$(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
}
Run Code Online (Sandbox Code Playgroud)

但我得到了ReflectionTypeLoadException,说Could not load file or assembly了一些参考组件(例如,Microsoft.AspNetCore.Antiforgery).

我如何为.NET Core应用程序加载程序集?

.net c# .net-core asp.net-core

9
推荐指数
1
解决办法
864
查看次数

标签 统计

asp.net-core ×2

c# ×2

.net ×1

.net-core ×1