[英]How to run unsafe code in “visual studio code”?
I am using Visual studio code and when I try to run an unsafe code it throws the following error ""message": Unsafe code may only appear if compiling with /unsafe"我正在使用 Visual Studio 代码,当我尝试运行不安全代码时,它会引发以下错误“消息”:仅当使用 /unsafe 编译时才会出现不安全代码
and as in visual studio, it does not have option like project->properties.和 Visual Studio 一样,它没有像 project->properties 这样的选项。
unsafe (C# Compiler Options) 不安全(C# 编译器选项)
To set this compiler option in the Visual Studio development environment Open the project's Properties page.在 Visual Studio 开发环境中设置此编译器选项 打开项目的属性页。
Click the Build property page.单击构建属性页。
Select the Allow Unsafe Code check box.选中允许不安全代码复选框。
To add this option in a csproj file Open the .csproj file for a project, and add the following elements:在 csproj 文件中添加此选项 打开项目的 .csproj 文件,并添加以下元素:
XML XML
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Method level方法级别
unsafe static void FastCopy(byte[] src, byte[] dst, int count)
{
// Unsafe context: can use pointers here.
}
Inline Block内联块
...
unsafe
{
// Unsafe context: can use pointers here.
}
Class Level班级
public unsafe class Blah {}
In the .csproj
file, just add在.csproj
文件中,只需添加
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
to any <PropertyGroup>
block.到任何<PropertyGroup>
块。
No need to add anything to task.json
.无需向task.json
添加任何task.json
。
All not working in my netcoreapp3.1 C# Project所有在我的 netcoreapp3.1 C# 项目中都不起作用
This helped (in .vscode/tasks.json):这有帮助(在 .vscode/tasks.json 中):
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/rest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"/unsafe"
],
"problemMatcher": "$msCompile"
},
works for the 'dotnet build' command, not for the green launch button适用于“dotnet build”命令,不适用于绿色启动按钮
also working if executed from the terminal: 'dotnet build -p:unsafe=true'如果从终端执行也可以工作:'dotnet build -p:unsafe=true'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.