更新到 .NET/EF Core 6 后,Azure DevOps 构建失败,具有长(64 位整数)id 的 ModelShapShot 失败
将 ASP.NET 从 5 更新到 6(使用实体框架和 SQL 服务器)后,我遇到了 Azure DevOps 的一个非常奇怪的问题。我的构建管道设置为使用 .NET 6.0.x 和池中的 windows-2022 代理。我的 EF Core dll 是 6.0.2。
该项目在本地构建良好,但在 Azure DevOps 上执行 .NET 构建任务时,出现编译错误。它抱怨“AppDbContextModelSnapshot.cs”文件。似乎从 .NET5 到 6 已将这些行添加到此文件中,从以下内容开始:
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
到此:
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"), 1L, 1);
注意:实体 PK 的类型是“long”。
此构建在本地运行,可以在本地正常迁移,但在部署到 Azure DevOps 进行构建时,会产生以下异常:
Data\Application\Migrations\AppDbContextModelSnapshot.cs(24,78):错误 CS1503:参数 2:无法从'long' 到 'int'
我可以手动编辑生成的代码以删除争论,但为什么它会抱怨?我在本地看不到代码有任何问题,也看不到这个转换来自哪里。根据智能感知告诉我的内容,这似乎很好:
为什么 Azure DevOps 上存在这种差异?
I'm getting a very strange issue with Azure DevOps after updating my ASP.NET from 5 to 6, which uses entity framework and SQL server. My build pipeline is set to use .NET 6.0.x, and the windows-2022 agent from the pool. My EF Core dlls are 6.0.2.
The project builds fine locally, but with the .NET build task on Azure devops, I get compilation errors. It complains about the 'AppDbContextModelSnapshot.cs' file. It seems going from .NET5 to 6 has added these lines to this file, going from this:
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
To this:
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"), 1L, 1);
Note: the type for the PK of the entity is a 'long'.
This builds runs locally, migrates fine locally, but on deployment to Azure DevOps for a build, produces these exceptions:
Data\Application\Migrations\AppDbContextModelSnapshot.cs(24,78): Error CS1503: Argument 2: cannot convert from 'long' to 'int'
I can manually edit the generated code to remove the arguements, but why is it complaining? I can't see anything wrong with the code locally, and cannot see where this conversion is coming from. It seems fine based on what intellisense is telling me:
Why is there this difference on Azure DevOps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果在我的 csproj 文件中,有两个对 EF Core 库的引用,一个是旧版本。在某些时候一定是一次糟糕的合并。
It turned out in my csproj file there where two references to the EF Core library, one to an older version. Must have been a bad merge at some point.