【问题标题】:Can I mix framework projects and .net standard projects in the same repository? Dotnet Pack command我可以在同一个存储库中混合框架项目和 .net 标准项目吗? dotnet 包命令
【发布时间】:2020-02-12 23:25:11
【问题描述】:

answer to this question 中,我需要将构建 yaml 从使用 Nuget 更改为使用 DotNet 这样 .net 标准项目才能正确打包(我希望)。然而,当我这样做时,我开始得到 ​​p>

错误 MSB4057:项目中不存在目标“pack”

对于框架项目。

我应该分离存储库还是有办法为不同的目标指定不同的打包命令?

我原来的 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

但我将 NuGetCommand@2 任务更改为

- task: DotNetCoreCLI@2
  inputs: 
    command: 'pack'
    outputDir: '$(Build.ArtifactStagingDirectory)/TestDir'

对于 Nuget 命令,我可以尝试使用 PackagesToPack 我要为 DotNet 命令更改什么?

[更新] 我试过了

- task: DotNetCoreCLI@2
  inputs:
    command: 'pack'
    projects: '**/*Standard.csproj'
    outputDir: '$(Build.ArtifactStagingDirectory)/OutputDir'

其中 *Standard 是 .net 标准项目。但是框架项目中仍然存在 MSB4057 错误

【问题讨论】:

  • 你也可以用packagesToPack:代替Projects:做dotnet pack。由于我们只需要打包 .net 标准项目,您可以传递类似:packagesToPack: '**/LibraryProjectName.csproj'
  • 就是这样。谢谢。
  • 如果新创建的包可以在您的项目中很好地使用,请随时告诉我。 (并且您可能需要clean the nuget cache 以避免旧缓存影响 nuget 行为。)

标签: azure-devops azure-pipelines


【解决方案1】:

该错误表明您正在尝试打包.net standard 项目和.net framework 项目,而您只需要打包.net 标准库项目。 (另外,dotnet pack 不应该用于打包一个非库项目。)

所以解决方法是在使用dotnet pack任务时指定要打包的项目。 .net core task 中的Pack 命令也支持packagesToPack 元素。

#packagesToPack: '**/*.csproj' # Required when command == Pack

通常格式为:

steps:

- task: DotNetCoreCLI@2  
  displayName: 'dotnet pack'
  inputs:
    command: pack
    packagesToPack: '**/ProjectName.csproj'
    configuration: Release
    versioningScheme: xxx
    minorVersion: xxx
    buildProperties: xxx
    ...

【讨论】:

    猜你喜欢
    • 2018-06-28
    • 1970-01-01
    • 2011-11-14
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多