Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can seem to get msbuild to build unsafe code blocks

Tags:

c#

msbuild

unsafe

msbuild doesn't seem to allow me build unsafe blocks even though my .csproj specify:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    ...
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

my build command is:

msbuild myProject.sln /p:Configuration=Release /p:Platform="Any CPU" /t:Clean,Build
like image 466
rethabile Avatar asked Aug 17 '16 09:08

rethabile


People also ask

What compiler does MSBuild use?

By default, MSBuild will attempt to only run the TypeScript compiler when the project's source files have been updated since the last compilation.

What is MSBuild and do I need it?

The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software.

What is unsafe code?

Unsafe code in general is a keyword that denotes a code section that is not handled by the Common Language Runtime(CLR). Pointers are not supported by default in C# but unsafe keyword allows the use of the pointer variables.

How do I create a project using MSBuild command line?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.


2 Answers

I added /p:AllowUnsafeBlocks=true to MSBuild command, as follow:

MSBuild some-project.csproj /p:AllowUnsafeBlocks=true

If you are in VSTS, you could just include the /p:AllowUnsafeBlocks=true in the parameter.

This works for me.

like image 69
stack247 Avatar answered Oct 23 '22 05:10

stack247


You showed that the property is set for the Debug configuration. One option is that it's missing for the Release configuration.

Also you specified the platform on the command line as "Any CPU" (with a space), while the build file requires "AnyCPU". This might also cause it to not being picked up.

like image 44
Joey Avatar answered Oct 23 '22 07:10

Joey