Skip to content

Instantly share code, notes, and snippets.

@sayedihashimi
Last active January 3, 2016 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayedihashimi/8511756 to your computer and use it in GitHub Desktop.
Save sayedihashimi/8511756 to your computer and use it in GitHub Desktop.
Sample which shows how to create a nuget pkg with a module which another nuget pkg uses
# Folders to ignore #
OutputRoot/

Sample which shows how to create a nuget pkg with a module which another nuget pkg uses


param(
[ValidateScript({Test-Path $_})]
$nugetPath = '.\tools\NuGet.exe',
$outputFolder = '.\OutputRoot',
$nugetDevRepoPath = 'C:\temp\nuget\localrepo',
[switch]
$preventCreationOfDevRepoFolder
)
$argMsg = @"
build.ps1 called with the following args:
outputFolder: [{0}]
nugetPath: [{1}]
"@
$argMsg -f $outputFolder, $nugetPath | Write-Verbose
if(!(Test-Path $outputFolder)){
mkdir $outputFolder
}
# delete any .nupkg files that are in the output folder
Get-ChildItem $outputFolder -Filter *.nupkg | Remove-Item
$nugetSpecFiles = @('sayed-module','consuming-module')
$nugetSpecFiles | ForEach-Object {
# nuget pack .\webjobs.nuspec -OutputDirectory ..\OutputRoot\ -NonInteractive
$nugetArgs = @()
$nugetArgs += 'pack'
$nugetArgs += ('.\{0}.nuspec' -f $_)
$nugetArgs += '-OutputDirectory'
$nugetArgs += $outputFolder
$nugetArgs += '-NonInteractive'
'Calling nuget.exe with the following args: [{0}]' -f ($nugetArgs -join ' ') | Write-Host
& $nugetPath $nugetArgs
}
if(!(Test-Path $nugetDevRepoPath) -and (-not $preventCreationOfDevRepoFolder) ){
mkdir $nugetDevRepoPath
}
if(Test-Path $nugetDevRepoPath){
# copy nuget packages to the dev repo
Get-ChildItem $outputFolder -Filter *.nupkg | Copy-Item -Destination $nugetDevRepoPath
}
param($installPath, $toolsPath, $package, $project)
'Calling New-Message from the dependant nuget package' | Write-Host
New-Message
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>consuming-module</id>
<version>0.1.0.0</version>
<authors>Sayed Ibrahim Hashimi</authors>
<owners>Sayed Ibrahim Hashimi</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<projectUrl>https://github.com/ligershark/webjobsvs</projectUrl>
<!--<iconUrl>http://msbuildbook.com/images/vsix-compress.png</iconUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
sample module in a nuget pkg
</description>
<!-- <releaseNotes></releaseNotes> -->
<copyright>Copyright 2014 All Rights Reserved</copyright>
<tags></tags>
<dependencies>
<dependency id="sayed-module" version="0.1.0.0" />
</dependencies>
</metadata>
<files>
<file src="cm-install.ps1" target="tools\install.ps1"/>
<file src="cm-readme.txt" target="content\Properties\consuming-module-readme.txt"/>
</files>
</package>
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>sayed-module</id>
<version>0.1.0.0</version>
<authors>Sayed Ibrahim Hashimi</authors>
<owners>Sayed Ibrahim Hashimi</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<projectUrl>https://github.com/ligershark/webjobsvs</projectUrl>
<!--<iconUrl>http://msbuildbook.com/images/vsix-compress.png</iconUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
sample module in a nuget pkg
</description>
<!-- <releaseNotes></releaseNotes> -->
<copyright>Copyright 2014 All Rights Reserved</copyright>
<tags></tags>
<!--<dependencies>
<dependency id="SampleDependency" version="1.0" />
</dependencies>-->
</metadata>
<files>
<file src="sm-init.ps1" target="tools\init.ps1"/>
<file src="sayed-module.psm1" target="tools\sayed-module.psm1"/>
<file src="sm-readme.txt" target="content\Properties\sayed-module-readme.txt"/>
</files>
</package>
[cmdletbinding()]
param()
function New-Message{
'Here is a new message' | Write-Host
}
Export-ModuleMember -Function *
param($installPath, $toolsPath, $package, $project)
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$moduleName = 'sayed-module'
# $importedModule = Get-Module | ?{ $_.Name -eq $moduleName }
if((Get-Module $moduleName)){
Remove-Module $moduleName
}
Import-Module (Join-Path -Path (Get-ScriptDirectory) -ChildPath ('{0}.psm1' -f $moduleName))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment