即使在 project.json 中将 allowunsafe 标志设置为 true 后,.NET Core 中的不安全代码编译错误 [英] Unsafe code compilation error in .NET Core even after setting allowunsafe flag to true in project.json
本文介绍了即使在 project.json 中将 allowunsafe 标志设置为 true 后,.NET Core 中的不安全代码编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的 .NET Core 应用程序中使用了一些不安全的代码.为此,我在 project.json 文件中进行了此更改:
I am using some unsafe code in my .NET Core app. For that, I had made this change in the project.json file:
"compilationOptions": {
"allowUnsafe": true,
}
但是,我仍然收到错误 CS0227:只有在使用/unsafe
编译时才会出现不安全的代码.
However, I still get the error CS0227: Unsafe code may only appear if compiling with /unsafe
.
我已经经历过这个:
推荐答案
注意:
此答案基于以 json
编写的早期 .Net Core/Standard 项目格式.对于新格式化的 csproj
请参阅 Ray 的回答.
NOTE:
This answer is based on earlier .Net Core/Standard project formats written in json
. For the new formatted csproj
see Ray's answer.
将 compilationOptions
更改为 buildOptions
:
"buildOptions": {
"allowUnsafe": true
}
这篇关于即使在 project.json 中将 allowunsafe 标志设置为 true 后,.NET Core 中的不安全代码编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文