Pergunta

How to compile a Visual Studio 2010 solution using xbuild that uses unsafe code?

Currently I get this error:

Implementation/MaximumImageColorClassifier.cs(35,13): error CS0227: Unsafe code requires the `unsafe' command line option to be specified

But running:

xbuild -unsafe [solution file]

or:

xbuild /unsafe [solution file]

Gives an error:

MSBUILD: error MSBUILD0004: Too many project files specified

xbuild help shows that that's the proper syntax:

xbuild /? ... xbuild [options] [project-file]

But there is no unsafe option, and no "generic" option to provide some compilation flags.

I saw this question: Can I pass an argument to msc through xbuild on the command line? but it has no definite answer and maybe there is a specific workaround for unsafe code?

Also, in my case xbuild is using dmcs compiler.

Foi útil?

Solução

Eventually, I've found the solution myself. It is to put:

    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>

in csproj file, under appropriate PropertyGroup (related to the configuration xbuild is using to build the solution). It is correctly interpreted and unsafe code compiles fine.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top