Kir*_*eed 5 nuget entity-framework-core azure-devops .net-standard .net-4.7.2
我成功地从框架 4.7.2 测试项目中调用了 .net 标准 2.0 库。

如果我使用我的 .net 标准 2.0 dll (SBD.Standard) 并创建一个引用它的新 winforms 项目,那么我会被要求添加
Microsoft.EntityFrameworkCore,
then Microsoft.EntityFrameworkCore.SqlServer,
then Microsoft.Data.SqlClient
Run Code Online (Sandbox Code Playgroud)
然后我的项目成功运行。(虽然如果自动添加额外的包会很理想)
但是,如果我尝试通过使用 Azure DevOps 构建的 Nuget 包分发我的库,则会出现问题。
但是,当我通过 Nuget(使用 Azure DevOps 创建 Nuget)分发标准库并将其包含在新项目中时,出现错误。
调用堆栈是
System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.0.19269.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. The system cannot find the file specified.
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at SBD.Standard.Helpers.HandyFuncs.QueueCommand(ApiDbContext connect, WorkTypeEnum workType, String
Run Code Online (Sandbox Code Playgroud)
导致问题的代码行是
public static int QueueCommand(ApiDbContext connect, WorkTypeEnum workType, string description, int jobId, int signature, XElement elem)
{
var command =
connect.EngineCommandQueues.SingleOrDefault(
c =>
(c.Status == 0|| c.Status == 2) &&
c.Signature == signature);
Run Code Online (Sandbox Code Playgroud)
我确实发现我需要安装以下软件包
Microsoft.EntityFrameworkCore 3.1.1
Microsoft.EntityFrameworkCore.SqlServer 3.1.1 which has a dependency on Microsoft.Data.SqlClient >=1.019269.1
Run Code Online (Sandbox Code Playgroud)
我看到 Microsoft.Data.SQLClient v1.0.19269.1 已安装
我尝试安装 System.Linq
我在 Nuget 中看到了 Microsoft.Data.SqlClient 的注释
在 Windows 上运行时,此库依赖于 .NET Framework 上的 Microsoft.Data.SqlClient.SNI
并安装了 Microsoft.Data.SqlClient.SNI v1.0.19235.1
我尝试将 Microsoft.Data.SqlClient 升级到 1.1 并且错误更改为
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception: Failed to load C:\Dev2\Combridge\SBD.ComBridge\UnitTestProjectStandard\bin\Debug\x86\SNI.dll ---> System.ComponentModel.Win32Exception: The specified module could not be found
at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 64
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()
at Microsoft.Data.SqlClient.SNILoadHandle..ctor() in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 36
at Microsoft.Data.SqlClient.SNILoadHandle..cctor() in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 17
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.TdsParser..cctor() in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:line 166
--- End of inner exception stack trace ---
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1411
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1310
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 357
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:line 773
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionClosed.cs:line 72
at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1860
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1853
at Microsoft.Data.SqlClient.SqlConnection.Open() in E:\agent1\_work\31\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1421
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at lambda_method(Closure , QueryContext )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
Run Code Online (Sandbox Code Playgroud)
[更新] 阅读这篇 GitHub 帖子,它似乎与 Azure Devops 有关
帖子提到
Win32Exception: Failed to load C:__source_code\repo1\Simplified\bin\x86\SNI.dll 所以它试图加载 sni.dll 的 32 位版本,但它不存在。
这让我怀疑您在 64 位系统上构建它,然后将文件传输到另一台机器。您需要为 x86 目标发布项目才能解决正确的本机依赖项。试一试。
我正在运行 Windows 10,所以我不明白为什么它会尝试加载 32 位版本的 sni.dll
我可以在 Azure Artifacts 中看到
Microsoft.Data.SqlClient.SNI 1.0.19235.1
[更新]
我从这个问题中看到,我需要强制 MSBuild 创建/更新包含必要绑定重定向的 YourProject.dll.config 文件。因此 Nuget 也应该创建该配置文件。我想知道这会如何影响事情。
我的 azure-pipelines.yml 是
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
Major: '2'
Minor: '0'
Patch: '0'
steps:
- task: NuGetToolInstaller@0
inputs:
versionSpec: '>=4.3.0'
checkLatest: true
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: NuGetCommand@2
inputs:
command: pack
packagesToPack: '**/*.csproj'
versioningScheme: byPrereleaseNumber
majorVersion: '$(Major)'
minorVersion: '$(Minor)'
patchVersion: '$(Patch)'
- task: NuGetCommand@2
inputs:
command: pack
packagesToPack: '**/*.vbproj'
versioningScheme: byPrereleaseNumber
majorVersion: '$(Major)'
minorVersion: '$(Minor)'
patchVersion: '$(Patch)'
- task: NuGetCommand@2
displayName: 'NuGet push'
inputs:
command: push
publishVstsFeed: 'SBDCommonFeed'
allowPackageConflicts: true
Run Code Online (Sandbox Code Playgroud)
[更新]
我尝试将 yaml 更改为使用 dotnet pack,但出现错误
[更新]
我尝试将 yaml 的 pack 部分替换为
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
selectOrConfig: 'config'
nugetConfigPath: '$(System.DefaultWorkingDirectory)/NuGet.config'
externalEndpoints: $(externalFeedCredential)
Run Code Online (Sandbox Code Playgroud)
当我单击按钮进行授权时,我收到一条消息:权限不足或资源丢失。即使我以存储库所有者的身份登录。
我想我需要学习在 externalEndpoints 中放入什么
[更新]
我试过这个
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
outputDir: '$(Build.ArtifactStagingDirectory)/TestDir'
Run Code Online (Sandbox Code Playgroud)
现在错误变成
error MSB4057: The target "pack" does not exist in the project.
Run Code Online (Sandbox Code Playgroud)
调查这个答案
尽管如果自动添加额外的包将是理想的。
假设我们有一个.net standard项目依赖于Microsoft.EntityFrameworkCore,Microsoft.EntityFrameworkCore.SqlServer和其他包。我们的预期行为是创建一个 nuget 包,其中的文件包含有关依赖项xx.nuspec的定义。
但是命令有一个问题nuget pack,它不能很好地用于 .net core/standard 项目。和nuget pack都dotnet pack可以成功创建.net standardnuget包,但pack successfully并不意味着包好。
由于上述问题的影响,创建的包nuget pack将丢失Package.nuspec文件中的一些依赖项。(将xx.nupkg重命名为xx.zip,然后我们可以查看包内的内容,我们会看到xx.nuspec文件)
上述步骤可能会导致运行时错误,例如missing assembly. 因此,为了理想地自动添加额外的包并避免丢失引用,我们建议dotnet pack使用 PackageReference 格式的项目命令。(无论是本地 dotnet pack 命令还是 Azure Devops Piepilne 中的 dotnet pack 任务)
| 归档时间: |
|
| 查看次数: |
10722 次 |
| 最近记录: |