即使在 project.json 中将 allowunsafe 标志设置为 true 后,.NET Core 中的不安全代码编译错误
Unsafe code compilation error in .NET Core even after setting allowunsafe flag to true in project.json
我在我的 .NET Core 应用程序中使用了一些不安全的代码。
为此,我在 project.json 文件中进行了以下更改:
"compilationOptions": {
"allowUnsafe": true,
}
但是,我仍然得到错误 CS0227: Unsafe code may only appear if compiling with /unsafe
。
我已经经历过这个:
注意:
这个答案是基于早期的 .Net Core/Standard 项目格式编写的 json
。对于新格式 csproj
.
将compilationOptions
改为buildOptions
:
"buildOptions": {
"allowUnsafe": true
}
在较新的 *.csproj
文件中,现在是:
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
任意 PropertyGroup
.
我在我的 .NET Core 应用程序中使用了一些不安全的代码。 为此,我在 project.json 文件中进行了以下更改:
"compilationOptions": {
"allowUnsafe": true,
}
但是,我仍然得到错误 CS0227: Unsafe code may only appear if compiling with /unsafe
。
我已经经历过这个:
注意:
这个答案是基于早期的 .Net Core/Standard 项目格式编写的 json
。对于新格式 csproj
将compilationOptions
改为buildOptions
:
"buildOptions": {
"allowUnsafe": true
}
在较新的 *.csproj
文件中,现在是:
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
任意 PropertyGroup
.