Search code examples
c#msbuildunsafe

I can seem to get msbuild to build unsafe code blocks


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

Solution

  • 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.