尝试将一个示例的 .Net FX4.8 控制台应用程序迁移到包引用,并出现错误。

huangapple go评论62阅读模式
英文:

Trying to migrate a sample .Net FX4.8 console app to package reference and getting error

问题

给定:
Nuget包:Microsoft.SqlServer.Types
Visual Studio 2019控制台应用程序.NET Framework 4.8

https://github.com/rodsantest1/SpatialDataSetupSol

上述项目是在从package.config迁移到包引用之前创建的。
https://devblogs.microsoft.com/nuget/migrate-packages-config-to-package-reference/

当我按照下面的图片所示进行迁移时,我遇到了一个错误。迁移后,SqlServerTypes在当前上下文中不存在,而在之前存在。

在这个非常简单的设置中,我需要做什么才能将它迁移到包引用?

尝试将一个示例的 .Net FX4.8 控制台应用程序迁移到包引用,并出现错误。

英文:

Given:
Nuget Package: Microsoft.SqlServer.Types
Visual Studio 2019 Console App .Net Framework 4.8

https://github.com/rodsantest1/SpatialDataSetupSol

The preceding project is prior to migrating to package references from package.config
https://devblogs.microsoft.com/nuget/migrate-packages-config-to-package-reference/

I'm getting an error when I do the migration as shown in image below. After migration SqlServerTypes doesn't exist in the current context where it did before.

What do I have to do to migrate it to package reference in this very minimal setup?

尝试将一个示例的 .Net FX4.8 控制台应用程序迁移到包引用,并出现错误。

答案1

得分: 1

看起来你正在尝试在旧的非 SDK 风格项目中使用 <PackageReference/>。我不确定这是否按设计工作,但根据我的经验,这种混合可能会导致奇怪的行为。

因此,我建议将项目转换为 SDK 风格(这包括将包列表移到 csproj 内部),然后应该按预期工作。在这里了解更多关于 SDK 风格项目的信息:https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview#project-files。

你也可以使用升级助手来转换你的项目。在 https://dotnet.microsoft.com/en-us/platform/upgrade-assistant 阅读更多信息。你可能需要在升级助手之后调整你的项目,至少将目标框架还原为 net48

英文:

It looks like that you are trying to use &lt;PackageReferece/&gt; in the old non-sdk-style project. I'm not sure if this shold work by design or not, but from my experience such a mix can lead to strange behaviour.

So, I can suggest to convert the project to the sdk-style (this includes moving package list inside the csproj) and this should work as expected. Read more about sdk-style projects here https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview#project-files.

You can also use Upgrade Assistant to convert your projects. Read more at https://dotnet.microsoft.com/en-us/platform/upgrade-assistant. You may need to adjust your project after upgrade assistant, at least revert target framework to net48.

huangapple
  • 本文由 发表于 2023年6月2日 08:17:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386457.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定