Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Create Nuget package for SSIS using MSBuild
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>_Dummy</id>
<version>1.0.0</version>
<authors>DBA</authors>
<owners>SpeakSQL</owners>
<licenseUrl>http://a.c</licenseUrl>
<projectUrl>http://a.c</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
</metadata>
</package>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Configuration properties - you can override these from the command line
-->
<PropertyGroup>
<DeployNugetProjectRoot Condition="'$(DeployNugetProjectRoot)' == ''">$(MSBuildProjectDirectory.TrimEnd('\'))</DeployNugetProjectRoot>
<DeployPackageName Condition="'$(DeployPackageName)' == ''">$(SSISProj)</DeployPackageName>
<DeployNugetNuSpecFileName Condition="'$(DeployNugetNuSpecFileName)' == ''">$(DeployPackageName).nuspec</DeployNugetNuSpecFileName>
<NuGetExe>$(NuGetExePath)</NuGetExe>
<NuGetExe Condition="'$(NuGetExe)' == ''">C:\MSBuild\.nuget\nuget.exe</NuGetExe>
<OutputPath>.\$(SSISProj)\bin\$(CONFIGURATION)</OutputPath>
<DeployNugetTemporaryDirectory Condition="'$(DeployNugetTemporaryDirectory)' == ''">$(OutputPath.TrimEnd('\'))\NuGet-temp</DeployNugetTemporaryDirectory>
<BUILD_NUMBER Condition="$(BUILD_NUMBER)==''">0</BUILD_NUMBER>
<MajorVersion Condition="'$(MajorVersion)'==''">1</MajorVersion>
<MinorVersion Condition="'$(MinorVersion)'==''">0</MinorVersion>
<RevisionVersion Condition="'$(RevisionVersion)'==''">0</RevisionVersion>
<DeployNugetPackageVersion Condition="'$(DeployNugetPackageVersion)' == ''">$(MajorVersion).$(MinorVersion).$(RevisionVersion).$(BUILD_NUMBER)</DeployNugetPackageVersion>
</PropertyGroup>
<!--
Establsh Context
This target figures out whether this is a web project or normal application, and whether it is being built in release mode.
It then discovers the location of NuGet.exe.
-->
<!--
Find NuGet.exe and the project NuSpec
-->
<Target Name="DeployNugetFindNuGetSettings">
<Error
Code="OCTO: 1001"
Text="OctoPack: Expected to find a NuGet spec file named $(DeployNugetNuSpecFileName) under $(MSBuildProjectDirectory). You can fix this error by adding a NuGet spec file with that name, or override the name of the file by setting a property called DeployNugetNuSpecFileName in your project."
Condition="!Exists('$(DeployNugetNuSpecFileName)')"
/>
<Error
Code="OCTO: 1002"
Text="OctoPack: Could not locate NuGet.exe. Please add a NuGet package reference for NuGet.CommandLine, or set the property DeployNugetNuGetExePath in your project. Current search path is: $(NuGetExe)"
Condition="!Exists('$(NuGetExe)')"
/>
<Message Importance="High" Text="NuGet.exe found: $(NuGetExe)"/>
</Target>
<!--
Packaging DB
-->
<Target Name="DeployNugetForDB" DependsOnTargets="DeployNugetFindNuGetSettings">
<Message Text="********************* start to create nuget package"/>
<RemoveDir Directories="$(DeployNugetTemporaryDirectory)" ContinueOnError="true" />
<MakeDir Directories="$(DeployNugetTemporaryDirectory)" />
<ItemGroup>
<ContentToPackage Include="$(OutputPath)\**\*" Exclude="$(OutputPath)\**\*.vshost.*;$(OutputPath)\**\*.nupkg" />
</ItemGroup>
<Copy
SourceFiles="@(ContentToPackage)"
DestinationFiles="@(ContentToPackage->'$(DeployNugetTemporaryDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"
/>
<Copy SourceFiles="$(DeployNugetNuSpecFileName)" DestinationFolder="$(DeployNugetTemporaryDirectory)" />
<Exec Command='"$(NuGetExe)" pack "$(DeployNugetTemporaryDirectory)\$(DeployNugetNuSpecFileName)" -OutputDirectory "E:\webhome\nuget-deploy\Packages" -basePath "$(DeployNugetTemporaryDirectory)" -Version "$(DeployNugetPackageVersion)" -NoPackageAnalysis' />
</Target>
</Project>
#requires -version 2.0
<#
.SYNOPSIS
Prepare projects to be able to build Nuget package using MSBuild.
.DESCRIPTION
Import MSBuild script for Nuget(DeployNugetForDB.targets) to project(.proj) files and copy Spec file(.nuspec) for those projects
1. Import DeployNugetForDB.targets to project(.proj) files in a folder
2. Copy Default.nuspec and modify contents and file name
.EXAMPLE
ImportTargetsForDB.ps1 -DeployNuget
This command install the reports in the ReportList.txt from the DeployDemo project to Reporting Service defined in the Debug Configuration.
.NOTES
Version History
v1.0 - HJLee - 7/7/2012 - Created intial version
v1.1 - SpeakSQL.wordpress.com - 6/6/2013 - Modified to work on SSIS.
#>
param(
[switch]$Version = $false,
[switch]$DeployNuget = $false,
[string]$Path = "."
)
$DeployNugetTarget = (gi "C:\MSBuild\.nuget\DeployNugetForDB.targets")
function Install-Targets
{
param(
[parameter(Position = 0, Mandatory = $true)]
$project,
[parameter(Position = 1, Mandatory = $true)]
$target,
[parameter(Position = 2)]
[string]$replace = ""
)
Write-Host ("Installing " + $target.BaseName + " Targets file import into project " + $project.Name)
$xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"
$xml = [xml](Get-Content $project.FullName)
$nsmgr = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xml.NameTable
$nsmgr.AddNamespace('a', $xmlns)
$imports = $xml.SelectNodes('//a:Import', $nsmgr)
<#
$imports | where { $_.Project -match $target.Name } | foreach-object {
Write-Host ("Removing old import: " + $_.Project)
$xml.Project.RemoveChild($_)
}
#>
if($replace -eq "") {
foreach($import in $imports) {
if($import.Project -match $target.Name) {
Write-Host ("Skip to add targets script ( '" + $target.Name + "' already exists )")
return;
}
}
}
else {
foreach($import in $imports) {
if($import.Project -match $replace) {
$xml.Project.RemoveChild($import)
}
}
}
#Write-Host ("The current project is: " + $project.FullName +" , Project parent directory: " + $project.Directory)
$importFile = $target.FullName
$import = $xml.CreateElement("Import", $xmlns);
#Copy-Item $target.FullName $project.Directory
#$importFile = ".\" + $target.Name
$import.SetAttribute("Project", $importFile);
$xml.Project.AppendChild($import);
$xml.Save($project.FullName)
if($replace -eq "") {
Write-Host ("Import is added for: " + $importFile)
}
else {
Write-Host ($replace + " is replaced with " + $importFile)
}
}
function Main
{
$PackageName = $env:JOB_NAME
$list = Get-ChildItem $Path *.proj
foreach($project in $list)
{
if($DeployNuget.isPresent) {
Install-Targets $project $DeployNugetTarget
$xml = [xml](Get-Content "C:\MSBuild\.nuget\Default.nuspec")
if($PackageName -eq "") {
$_PackageName = ($project.BaseName + "")
}
else {
$_PackageName = $PackageName
}
$xml.Package.metadata.id = $_PackageName
$xml.Package.metadata.description = ("Package build time is " + [datetime]::Now )
$newname = ($project.FullName | split-path) + "\" + $_PackageName + ".nuspec";
#Write-Host ("Copy nuget spec file as " + $newname)
$xml.Save($newname )
}
}
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment