I can seem to get msbuild to build unsafe code blocks
Asked Answered
B

2

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
Balladmonger answered 17/8, 2016 at 9:7 Comment(1)
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.Callender
C
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.

Chalcocite answered 17/8, 2016 at 9:9 Comment(2)
FYI, ensuring this was all correct did not help me. The following answer did (adding /p:AllowUnsafe.... to the MSBuild command)Necrophilism
@BRebey: This would still indicate that your project configuration is wrong.Chalcocite
S
14

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.

Stall answered 8/6, 2018 at 7:24 Comment(0)
C
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.

Chalcocite answered 17/8, 2016 at 9:9 Comment(2)
FYI, ensuring this was all correct did not help me. The following answer did (adding /p:AllowUnsafe.... to the MSBuild command)Necrophilism
@BRebey: This would still indicate that your project configuration is wrong.Chalcocite

© 2022 - 2024 — McMap. All rights reserved.