Due to security issues with ADO in my workplace I'm unable to restore GIT submodules during project build. One dependency we will be needing is a set of common and stack-specific configuration files. I was hoping to create a method to share these configuration JSON files via an internal private artifact (NuGet package).
In the project folder, I have the following structure:
readme.txt
bla.yml
bla.targets
/content
common.configuration.json
dev.common.configuration.json
And a package.nuspec file:
<?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.targets:
<?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>
My build pipeline YAML is:
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}'
When I view the .nuget\packages folder, the restored package does have the files, and the readme.txt file appears as expected, but the .json files do not show up anywhere in the referencing project itself.
Is there any way to have those restore into a path within the project that is using that package? To have the content files included in the referencing project's build?
If you use
Install-Package BlaID -version <version>to install the package, the package will be restored in the project/packages folder.You can copy the files needed to target folder afterwards.
Or, to restore the package to target folder, you can use
nuget installwith-OutputDirectoryspecified. You can also add-ExcludeVersionto install the package to a folder named with only the package name and not the version number.Files restored, you can refer to the Nuget install doc for the details.