Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call unsafe code from ASP.NET xproj

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:

enter image description here

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?

like image 664
James Ko Avatar asked Aug 25 '15 18:08

James Ko


Video Answer


1 Answers

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.

like image 112
James Ko Avatar answered Nov 12 '22 12:11

James Ko