我有一个最初是为 .NET 6 创建的项目,但后来我需要将其降级到 .NET 5。我在项目属性中更改了目标框架并尝试编译。结果我收到了一堆错误:
GlobalUsings.g.cs(2,1,2,29): error CS8773: Feature 'global using directive' is not available in C# 9.0. Please use language version 10.0 or greater.
Run Code Online (Sandbox Code Playgroud)
文件 GlobalUsings.g.cs 是自动创建的,并且每次编译后都会重新出现。
我已在 Visual Studio 2019 中下载并安装了 .NET Core 5.0 SDK (v5.0.100-preview.1)。但它在 Target 框架中不可用。我错过了什么吗?
我是否应该Record
用于在控制器和服务层之间移动数据的所有 DTO 类?
我是否应该Record
用于所有请求绑定,因为理想情况下我希望发送到控制器的请求对于我的 asp.net api 是不可变的
什么是记录?https://anthonygiretti.com/2020/06/17/introducing-c-9-records/
public class HomeController
{
public IHttpAction Search([FromBody] SearchParameters searchParams)
{
_service.Search(searchParams);
}
}
Run Code Online (Sandbox Code Playgroud)
应该发SearchParameters
一个Record
?
ref
编译.NET 5.0 应用程序时的文件夹是什么?
我的意思是这个:
[project_path]\bin\Debug\net5.0\ref\
Run Code Online (Sandbox Code Playgroud) 我尝试在 Microsoft Visual Studio 2019 中运行我的 ASP.NET Core 项目并收到此错误:“无法连接到 Web 服务器‘IIS Express ’”
在 .NET<5 和 .NET Core 3.1 中,以下代码
var d = new Dictionary<string, int> { { "a", 0 }, { "b", 0 }, { "c", 0 } };
foreach (var k in d.Keys)
{
d[k]+=1;
}
Run Code Online (Sandbox Code Playgroud)
投掷
System.InvalidOperationException:集合已修改;枚举操作可能无法执行。
当面向 .NET 5 时,代码段不再抛出。
发生了什么变化?
我未能在Breaking changes in .NET 5和Performance Improvements in .NET 5 中找到答案。
是不是和什么有关ref readonly T
?
我已经下载并安装了v5.0.0-preview.5
。我的项目正在瞄准net5.0
但C# 9.0
不起作用。我怎样才能启用C# 9.0
?
我正在将代码从 .NET 3.0 升级到 .NET 5.0,这对 sintaxis 做了很大的改变。在我之前的代码中,这是在 AZURE FUNCTIONS .NET 5.0 隔离中构建的 http 请求,构建了一个采用参数的 GET api。
这是我之前来自 .NET 3.0 的代码
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
byte[] RSA_Key_to_Correct = new byte[0x80];
string array_var = req.Query["array_var"];
string i = req.Query["i"];
string incrementing_value = req.Query["incrementing_value"];
}
Run Code Online (Sandbox Code Playgroud)
我只是找不到一种方法来使用req从 api 调用中获取参数,就像在 .NET 3.0 上完成的那样string i = req.Query["i"];
在 .NET …
通常我将以下图像用于 .net core 3.1 并且它工作正常。
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
Run Code Online (Sandbox Code Playgroud)
我出于实验原因启动了一个新的 .net 5 项目并创建dockerfile
了以下内容
FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
Run Code Online (Sandbox Code Playgroud)
并有以下问题:
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.2s
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim 0.2s
=> CANCELED [build 1/7] FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.0s
=> [internal] load build context 0.0s
=> ERROR [base 1/2] FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim
Run Code Online (Sandbox Code Playgroud) 我在曾经为 .NET Framework 4.5 构建但现在正在为 .NET 5 构建的 WPF 程序中有以下警告。
Warning NETSDK1137 It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK.
Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'.
ListEditor
C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 376
Run Code Online (Sandbox Code Playgroud)
单击警告会Microsoft.NET.Sdk.DefaultItems.targets
在第 376 行打开文件。该文件以注释开头DO NOT MODIFY
。
<!--
***********************************************************************************************
Microsoft.NET.Sdk.DefaultItems.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or …
Run Code Online (Sandbox Code Playgroud)