在同一Nuget软件包中以.NET 4.7.2和.NET 6.0构建?
我可以为.NET Framework 4.7.2项目创建一个Nuget软件包。
# .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://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
name: $(Date:yy).$(Date:MM).$(Rev:r)
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
displayName: NuGet restore
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: NuGetCommand@2
displayName: 'NuGet pack'
inputs:
command: 'pack'
packagesToPack: '**/*.csproj'
versioningScheme: 'byBuildNumber'
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/$(BuildConfiguration)/**'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: NuGetCommand@2
displayName: 'NuGet push'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
allowPackageConflicts: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
但是我想为.net 6.0构建一个版本。我感到迷路了。很抱歉这样问这个,但是我该怎么办。多个构建定义?多个任务?
I'm able to create a NuGet package for .NET Framework 4.7.2 project.
# .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://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
name: $(Date:yy).$(Date:MM).$(Rev:r)
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
displayName: NuGet restore
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: NuGetCommand@2
displayName: 'NuGet pack'
inputs:
command: 'pack'
packagesToPack: '**/*.csproj'
versioningScheme: 'byBuildNumber'
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/$(BuildConfiguration)/**'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: NuGetCommand@2
displayName: 'NuGet push'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
allowPackageConflicts: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
But I would like to build a version for .NET 6.0. I feel lost. I'm sorry to ask this like this but what should I do. Multiple build definition? Multiple tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用多目标支持,您需要始终如一地使用新的构建工具链。也就是说,您需要使用.NET SDK而不是旧的msbuild/nuget.exe工具构建和包装。
因此,首先,您需要使用构建项目文件。要同时定位
net472
和net6.0
,请使用< targetFrameWorks>
element(与< targetframework> 元素)。您还应将
< iSpackable>/iSpackable>
用于您不想包装到.nupkg文件中的任何项目,因为多目标是通过在 solution包装中完成的等级。添加
Microsoft.netframework.ReferenceSemblies
作为私人资产可确保您的.NET Framework 4.7.2构建即使在Linux和MacOS上也可以正常工作。您需要的只是。net 6+ sdk 在构建计算机上。您需要使用
dotnet build
build < /a>进行建筑物和dotnet pack
进行包装。这两个都应在解决方案文件上执行。
To use the multi-targeting support, you need to consistently use the new build toolchain. That is, you need to build and pack with the .NET SDK rather than the old MSBuild/NuGet.exe tools.
So, firstly you need to be using the new .csproj format to build your project files. To target both
net472
andnet6.0
, use the<TargetFrameworks>
element (as opposed to<TargetFramework>
element). You also should set<IsPackable>false</IsPackable>
for any projects that you don't want to pack into .nupkg files, since multi-targeting is done by packing at the solution level.Adding
Microsoft.NETFramework.ReferenceAssemblies
as a private asset ensures your .NET Framework 4.7.2 build will work even on Linux and macOS. All you need is the .NET 6+ SDK on the build machine.You need to use the
dotnet build
to do the building anddotnet pack
to do the packing. Both of these should be executed on the solution file.