如何在 ADO 中仅使用 .json 文件创建 NuGet 包,没有 csproj 或二进制文件

问题描述 投票:0回答:1

由于工作场所中 ADO 的安全问题,我无法在项目构建期间恢复 GIT 子模块。我们需要的一个依赖项是一组通用且特定于堆栈的配置文件。我希望创建一种方法来通过内部私有工件(NuGet 包)共享这些配置 JSON 文件。

在项目文件夹中,我具有以下结构:

readme.txt
bla.yml
bla.targets
/content
   common.configuration.json
   dev.common.configuration.json

还有 package.nuspec 文件:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
     <id>BlaID</id>
     <version>1.0.0</version>
     <authors>Bla</authors>
     <owners>Bla</owners>
 
     <releaseNotes>Initial creation</releaseNotes>
 
     <description>Common configuration for all layers bla</description>
 
     <tags>bla tags</tags>
  </metadata>
 
  <files>
     <file src="readme.txt" target="" />
     <file src="content\common.configuration.json" target="content" />
     <file src="content\dev.common.configuration.json" target="content" />
  </files>
</package>

Bla.目标:

<?xml version="1.0" encoding="utf-8"?>
  <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="CreatePackage">
    <PropertyGroup>
      <Configuration>Release</Configuration>
      <PackageSource>bin$(Configuration)\Package</PackageSource>
      <NuSpecPath>$(MSBuildProjectName).nuspec</NuSpecPath>
    </PropertyGroup>
  
    <RemoveDirDirectories="$(PackageSource)"/>

    <Copy SourceFiles="$(NuSpecPath)" DestinationFolder="$(PackageSource)"/>
    <Copy SourceFiles="content\dev.common.configuration.json" DestinationFolder="$(PackageSource)\configuration"/>
    <Copy SourceFiles="content\rc.common.configuration.json" DestinationFolder="$(PackageSource)\configuration"/>
    <Copy SourceFiles="content\qa.common.configuration.json" DestinationFolder="$(PackageSource)\configuration"/>
    <Copy SourceFiles="content\prod.common.configuration.json" DestinationFolder="$(PackageSource)\configuration"/>
  </Target>
</Project>

我的构建管道 YAML 是:

trigger:
  branches:
    include:
      - develop
      - release/*
      - story/*

variables:
  - name: isRelease
    value: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/release') }}
  - name: isDevelop
    value: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}
jobs:
- job:
  displayName: Build
  steps:
    - task: NuGetCommand@2
      inputs:
        command: 'pack'
        packagesToPack: '**/package.nuspec'
        versioningScheme: 'byPrereleaseNumber'
        majorVersion: '1'
        minorVersion: '0'
        patchVersion: '0'
   
    - task: NuGetCommand@2
      condition: or(eq(variables.isRelease, true), eq(variables.isDevelop, true))
      inputs:
        command: 'push'
        packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
        nuGetFeedType: 'internal'
        publishVstsFeed: '{the feed}'

当我查看 .nuget\packages 文件夹时,恢复的包确实包含文件,并且 readme.txt 文件按预期显示,但 .json 文件不会显示在引用项目本身的任何位置。

有什么方法可以将它们恢复到使用该包的项目内的路径中吗?要将内容文件包含在引用项目的构建中吗?

azure-devops nuget nuget-package azure-artifacts
1个回答
0
投票

如果您使用

Install-Package BlaID -version <version>
安装软件包,软件包将恢复到project/packages文件夹中。

之后您可以将需要的文件复制到目标文件夹。

或者,要将包恢复到目标文件夹,您可以使用

nuget install
并指定
-OutputDirectory
。如果不需要文件夹,您也可以添加
-ExcludeVersion

.\nuget.exe install BlaID -Version <version> -Source <source> -OutputDirectory <targetfolder> -ExcludeVersion

文件已恢复,具体可以参考Nuget安装文档

© www.soinside.com 2019 - 2024. All rights reserved.