.net 在.csproj 文件中开启unsafe

2021-07-27  本文已影响0人  ansey

错误情况

.net 工程使用unsafe报错 :

error CS0227: 不安全代码只会在使用 /unsafe 编译的情况下出现

解决方案

对于非IDE环境,需要在配置中添加选项。
在.csproj 文件中添加 , 允许 Release 、Debug 中启用unsafe模式。

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>
    
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>
上一篇 下一篇

猜你喜欢

热点阅读