我有一个 .NET 6 WPF 项目,无法弄清楚发生了什么变化,因为ProductVersion
我的程序集突然包含 git commit 哈希。
我的项目文件总是这样,我还更新了版本信息:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
...
<Version>0.9.2</Version>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
然后,在我的代码中,我使用以下命令将版本获取为字符串:
string? productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly()!.Location).ProductVersion;
Run Code Online (Sandbox Code Playgroud)
这总是返回预期的版本,例如0.9.2
,与项目文件中设置的版本完全相同。但有些事情发生了变化,现在看起来像这样:0.9.2+abf5b643b64475a8b1d7d89284e3478b1ba4a431
。这也是显示在资源管理器中 .dll 和 .exe 文件的“详细信息”选项卡上的内容。
我会定期更新 Visual Studio,以便接收我在其他项目中使用的 .NET 8 的更新,因此它可能与某些更新有关。但我不知道究竟发生了什么变化,也不知道如何定义ProductVersion
不包含 git 提交哈希(是的,它是提交哈希)。也有一段时间没有参与 WPF 项目了,所以不知道这种行为何时改变。
讽刺的是,我过去需要 git 提交,所以必须付出一些额外的努力才能使其可用,尽管缩写为 8 个字符。
有任何想法吗?
我已将我的应用程序迁移到 .Net 8,并使用 ubuntu 22.04.3 LTS VPS 来托管我的 Web 应用程序。
我正在尝试在 VPS 上安装 .net 8,但无法安装
我已经尝试过微软的脚本安装,但没有成功
我已经尝试过microsoft 的Debian 安装,但没有成功
当我运行 ubuntu 的基本命令时
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-8.0
Run Code Online (Sandbox Code Playgroud)
即使更新和升级 ubuntu 后,我也会遇到以下错误
我使用 C# 12。在 C# 12 中我可以使用主构造函数:
public class UserService(IUnitOfWork uow) : IUserService
{
}
Run Code Online (Sandbox Code Playgroud)
在 C# 12 之前,我对构造函数中注入的项使用 null 检查:
public class UserService : IUserService
{
private readonly IUnitOfWork _uow;
public UserService(IUnitOfWork uow)
{
ArgumentNullException.ThrowIfNull(uow);
_uow = uow;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我如何在 C# 12 中进行 null 检查?
是否需要对主构造函数使用快速失败?
今天早上我打开了 Visual Studio 2022 项目,但由于出现以下错误而无法让它继续运行:
CS9057 分析器程序集 'C:\Program Files\dotnet\sdk\8.0.100-preview.6.23330.14\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll '引用编译器的版本'4.7.0.0',它比当前运行的版本'4.6.0.0'更新。”
我目前正在使用Microsoft Visual Studio Community 2022 (64-bit) Version 17.6.5
我的项目文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Analyzers" Version="6.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="6.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.16" />
<PackageReference Include="MudBlazor" Version="6.2.3" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我最近安装了Microsoft Visual Studio Community 2022 (64-bit) Version 17.7.0 Preview 3.0
包含.NET 8 SDK
. 这似乎是导致分析器引用冲突的原因。
我无法找到文档来帮助我将分析器引用更改回正确的版本,并且似乎没有任何方法可以在Nuget …
我的CPU是AMD Ryzen 7 7840H,支持AVX-512指令集。当我运行.NET8程序时, 的值为Vector512.IsHardwareAccelerated
true。但System.Numerics.Vector<T>
仍然是256位,并没有达到512位。Vector<T>
为什么类型长度没有达到 512 位?目前是否不支持,或者我需要调整配置吗?
示例代码:
TextWriter writer = Console.Out;
writer.WriteLine(string.Format("Vector512.IsHardwareAccelerated:\t{0}", Vector512.IsHardwareAccelerated));
writer.WriteLine(string.Format("Vector.IsHardwareAccelerated:\t{0}", Vector.IsHardwareAccelerated));
writer.WriteLine(string.Format("Vector<byte>.Count:\t{0}\t# {1}bit", Vector<byte>.Count, Vector<byte>.Count * 8));
Run Code Online (Sandbox Code Playgroud)
检测结果:
Vector512.IsHardwareAccelerated: True
Vector.IsHardwareAccelerated: True
Vector<byte>.Count: 32 # 256bit
Run Code Online (Sandbox Code Playgroud) 为什么C# 12 中的主构造函数以相反的顺序执行?
\n至少可以说这是一个突破性的改变......
\n例子:
\nnamespace Whatever;\n\n[TestClass]\npublic class UnitTestTemp\n{\n [TestMethod]\n public void TestMethod1() // PASS // is expected, 1st is 1, 2nd is 2\n {\n using var stream = new MemoryStream(new byte[] { 1, 2, 3, 4 });\n\n var classicDerived = new ClassicDerived(stream);\n\n Console.WriteLine(classicDerived.Value1);\n Console.WriteLine(classicDerived.Value2);\n\n Assert.AreEqual(1, classicDerived.Value1);\n Assert.AreEqual(2, classicDerived.Value2);\n }\n\n [TestMethod]\n public void TestMethod2() // FAIL // is opposite, 1st is 2, 2nd is 1\n {\n using var stream = new MemoryStream(new byte[] { …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个新的 ASP.NET Core 8 Web API。在我之前使用 .NET 6 或 .NET 7 的项目中,我可以使用:
services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
});
services.AddVersionedApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
Run Code Online (Sandbox Code Playgroud)
现在,该软件包Microsoft.AspNetCore.Mvc.ApiExplorer
已被弃用,我将其替换为新软件包Asp.Versioning.Mvc.ApiExplorer
,但没有AddVersionedApiExplorer
.
在 Swagger 的配置中,我有以下代码:
public class ConfigureSwaggerOptions : IConfigureNamedOptions<SwaggerGenOptions>
{
private readonly IApiVersionDescriptionProvider _provider;
public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider)
{
_provider = provider;
}
public void Configure(SwaggerGenOptions options)
{
foreach (var description in _provider.ApiVersionDescriptions)
{
options.SwaggerDoc(
description.GroupName,
CreateVersionInfo(description));
} …
Run Code Online (Sandbox Code Playgroud) 使用 .NET 8 RC2 和 EF Core
我创建了一个动态查询并执行了该查询,结果出现以下错误
Microsoft.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '$'.
Incorrect syntax near '$'.
Incorrect syntax near '$'.
Run Code Online (Sandbox Code Playgroud)
如果我运行.ToQueryString()
查看生成的查询,我会得到这个。
DECLARE @__startDate_0 smalldatetime = '2023-10-26T00:00:00';
DECLARE @__endDate_1 smalldatetime = '2023-10-26T00:00:00';
DECLARE @__siteNos_2 nvarchar(4000) = N'[15,42,56,74,89,98,102,104,109,113,114,115,116,118,120,121,122,123,124,124,125,127,128,129,130,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,156,157,158,159,161,162,163,164,165,167,169,170,171,172,173,175,176,177,178,179,180,181,182,183,185,186,187,188,189,190,191,192,193,194,195,196,197,199,200,201,202,205,206,207,208,209,210,211,212,213,214,215,216,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,244,245,246,247,248,249,250,251,252,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,295,296,296,297,300,301,303,304,305,306,307,308,309,310,311,312,313,316,317,318,319,320,321,322,323,324,325,326,328,331,333,334,335,338,339,340,341,342,343]';
DECLARE @__startTime_3 time = '07:00:00';
DECLARE @__endTime_4 time = '22:00:00';
DECLARE @__upperLimit_5 smallint = CAST(30000 AS smallint);
DECLARE @__lowerLimit_6 smallint = CAST(0 AS smallint);
DECLARE @__stationIds_7 nvarchar(4000) = N'[117,116,98]';
DECLARE @__courseIds_8 nvarchar(4000) = N'[7]';
SELECT [o].[order_no], [o].[Bumped], [o].[Check_no], [o].[checkback], [o].[Course], …
Run Code Online (Sandbox Code Playgroud) 我正在使用 C# 12。在 C# 12 中我可以使用主构造函数:
实施1:
public class Calculation(int a,int b)
{
public int Addition() => a + b;
public int Subtraction() => a - b;
}
Run Code Online (Sandbox Code Playgroud)
实施2:
public class Calculation(int a,int b)
{
private int _a { get; init; } = a;
private int _b { get; init; } = b;
public int Addition() => _a + _b;
public int Subtraction() => _a - _b;
}
Run Code Online (Sandbox Code Playgroud)
当我像这样调用这个方法时:
console.WriteLine(new Calculation(10,25).Addition());
Run Code Online (Sandbox Code Playgroud)
两种实现都工作正常,所以我想知道使用较长的实现 2 相对于较短的实现 1 是否有任何优势。
我有一个 ASP.NET Core Web API,一直在 Azure 应用服务 Windows 平台上运行。这个应用程序的目标是 .NET 7,今天我将其更新为目标 .NET 8。它在本地编译和运行良好。
根据此公告,.NET 8 现已在 Azure 应用服务上提供:https ://azure.github.io/AppService/2023/11/14/dotnet8-ga.html
我将应用程序部署到 Azure 应用服务,然后将 .NET 版本更改为 .NET 8 - 如下所示:
这不起作用,我不断收到以下错误:
ANCM 无法找到本机依赖项
然后我在 Reddit 上找到了这篇文章: https: //www.reddit.com/r/dotnet/comments/17v7qb5/http_error_50031_ancm_failed_to_find_native/
因此,我继续安装ASP.NET Core .NET 8 x64
并x86
通过高级工具下的 Kudu - 如下所示:
然后,我多次在 Azure 应用服务上停止并重新启动该应用程序,但它仍然无法正常工作。当我尝试访问 API 上的端点时,它旋转了很长时间,并返回“服务不可用”错误,但根据 Azure 上的应用程序仪表板,它已启动并正在运行。
有什么建议么?还有其他人遇到升级到 .NET 8 的问题吗?
PS:我的 API 应用程序的部署是通过 GitHub 操作完成的,我确实将 .NET 版本更新到 .NET 8 - 见下文:
.net-8.0 ×10
c# ×8
c#-12.0 ×3
.net ×2
.net-6.0 ×2
asp.net ×2
asp.net-core ×2
avx512 ×1
azure ×1
blazor ×1
constructor ×1
dependencies ×1
fail-fast ×1
intrinsics ×1
simd ×1
sql-server ×1
ubuntu ×1