How to call unsafe code from ASP.NET xproj

杀马特。学长 韩版系。学妹 提交于 2019-12-05 18:02:40

问题


I created a class library today with the new Class Library (Package) templates in Visual Studio 2015. Apparently it uses a fancy new project format, the ASP.NET xproj, for building the package. While that's fine by me, how do I call unsafe code from the library? I looked into Project > Properties > Build, where the option to toggle unsafe code should be, but all I got was this:

So yeah, no such luck. I even tried pasting "<AllowUnsafeBlocks>true</AllowUnsafeBlocks>" manually into the .xproj file, but the compiler still complains.

Is it possible to enable this without creating another non-xproj assembly for the unsafe methods?


回答1:


The ASP.NET 5 tools are not documented nearly well enough, but after scouring Google for half an hour I came across the solution.

In your project.json file, add this line:

{
    "buildOptions": { "allowUnsafe": true }
}

Source.



来源:https://stackoverflow.com/questions/32211739/how-to-call-unsafe-code-from-asp-net-xproj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!