11

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
rethabile
  • 3,029
  • 6
  • 34
  • 68
  • You did not configure the project correctly, common mistake. Use Project > Properties > Build tab. Note the comboboxes at the top of the property page. Change the one labeled "Configuration" to "Release". Now tick the option. – Hans Passant Aug 17 '16 at 10:13

2 Answers2

13

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.

stack247
  • 5,579
  • 4
  • 41
  • 64
10

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.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • FYI, ensuring this was all correct did not help me. The following answer did (adding /p:AllowUnsafe.... to the MSBuild command) – BRebey May 10 '19 at 21:24
  • @BRebey: This would still indicate that your project configuration is wrong. – Joey May 11 '19 at 22:02