Permalink
Browse files

Initial add

  • Loading branch information...
0 parents commit 9c9bf63f6052784e26300de40e1c6802d718eafb @PaulStovell PaulStovell committed Jan 9, 2012
Showing with 394 additions and 0 deletions.
  1. +56 −0 .gitignore
  2. +9 −0 build.ps1
  3. +26 −0 source/OctoPack.nuspec
  4. +3 −0 source/content/OctoPack-Readme.txt
  5. +106 −0 source/targets/OctoPack.targets
  6. +73 −0 source/tools/Install.ps1
  7. +121 −0 source/tools/MSBuild.psm1
@@ -0,0 +1,56 @@
+*.*scc
+*.FileListAbsolute.txt
+*.aps
+*.bak
+*.[Cc]ache
+*.clw
+*.eto
+*.exe
+*.fb6lck
+*.fbl6
+*.fbpInf
+*.ilk
+*.lib
+*.log
+*.ncb
+*.nlb
+*.obj
+*.patch
+*.pch
+*.pdb
+*.plg
+*.[Pp]ublish.xml
+*.rdl.data
+*.sbr
+*.scc
+*.sig
+*.sqlsuo
+*.suo
+*.svclog
+*.tlb
+*.tlh
+*.tli
+*.tmp
+*.user
+*.vshost.*
+*DXCore.Solution
+*_i.c
+*_p.c
+Ankh.Load
+Backup*
+CVS/
+PrecompiledWeb/
+UpgradeLog*.*
+[Bb]in/
+[Dd]ebug/
+[Oo]bj/
+[Rr]elease/
+[Tt]humbs.db
+_UpgradeReport_Files
+_[Rr]e[Ss]harper.*/
+hgignore[.-]*
+ignore[.-]*
+svnignore[.-]*
+lint.db
+build
+tools/TestResult.xml
@@ -0,0 +1,9 @@
+$Version = 1
+
+do {
+ $Version = $Version + 1
+} while ( Test-Path (".\build\OctoPack.1.0." + $Version + ".nupkg" ) )
+
+.\tools\NuGet.exe pack source\OctoPack.nuspec -OutputDirectory build -Version ("1.0." + $Version) -BasePath source
+
+# .\tools\NuGet.exe push (".\build\OctoPack.1.0." + $Version + ".nupkg") "31f41c07-78c7-4f87-adb4-b3bd8aabb992"
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+ <metadata>
+ <version>1.0.0</version>
+ <authors>Octopus Deploy</authors>
+ <owners>Octopus Deploy</owners>
+ <licenseUrl>http://octopusdeploy.com/</licenseUrl>
+ <projectUrl>http://octopusdeploy.com/</projectUrl>
+ <id>OctoPack</id>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>
+ Octopus is an automated deployment tool powered by NuGet (octopusdeploy.com). This tool adds a post-build activity to your Visual Studio project,
+ so that an Octopus-compatible NuGet package is produced in the Bin directory whenever a Release build completes.
+ </description>
+ <dependencies>
+ <dependency id="NuGet.CommandLine" version="1.6.0" />
+ </dependencies>
+ </metadata>
+
+ <files>
+ <file src="content\OctoPack-Readme.txt" target="content\OctoPack-Readme.txt" />
+ <file src="tools\Install.ps1" target="tools\Install.ps1" />
+ <file src="tools\MSBuild.psm1" target="tools\MSBuild.psm1" />
+ <file src="targets\OctoPack.targets" target="targets\OctoPack.targets" />
+ </files>
+</package>
@@ -0,0 +1,3 @@
+OctoPack has to create this file, because NuGet will only run the custom
+Install.ps1 script if a content file exists. The Install.ps1 should have
+removed this file, but since it hasn't, please delete it manually.
@@ -0,0 +1,106 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <BuildDependsOn>
+ $(BuildDependsOn);
+ OctopusEstablishContext
+ </BuildDependsOn>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <_CopyWebApplicationDependsOn>
+ $(_CopyWebApplicationDependsOn);
+ OctopusEstablishContext
+ </_CopyWebApplicationDependsOn>
+ </PropertyGroup>
+
+ <!--
+ Configuration properties - you can override these from the command line
+ -->
+ <PropertyGroup>
+ <OctopusProjectRoot Condition="'$(OctopusProjectRoot)' == ''">$(MSBuildProjectDirectory.TrimEnd('\'))</OctopusProjectRoot>
+ <OctopusPackageConfiguration Condition="'$(OctopusPackageConfiguration)' == ''">Release</OctopusPackageConfiguration>
+ <OctopusNuSpecFileName Condition="'$(OctopusNuSpecFileName)' == ''">$(MSBuildProjectFullPath)</OctopusNuSpecFileName>
+ <OctopusNuGetExePath Condition="'$(OctopusNuGetExePath)' == ''">$(OctopusProjectRoot)\..\packages\NuGet.CommandLine*\**\Tools\NuGet.exe;$(OctopusProjectRoot)\..\..\packages\NuGet.CommandLine*\**\Tools\NuGet.exe;$(OctopusProjectRoot)\..\..\..\packages\NuGet.CommandLine*\**\Tools\NuGet.exe</OctopusNuGetExePath>
+ <OctopusTemporaryDirectory Condition="'$(OctopusTemporaryDirectory)' == ''">$(OutputPath.TrimEnd('\'))\NuGet-temp</OctopusTemporaryDirectory>
+ <OctopusPackageVersion Condition="'$(OctopusPackageVersion)' == ''">1.0.0</OctopusPackageVersion>
+ <OctopusWebConfigFile Condition="'$(OctopusWebConfigFile)' == ''">$(OctopusProjectRoot)\Web.config</OctopusWebConfigFile>
+ </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.
+ -->
+ <Target Name="OctopusEstablishContext">
+ <PropertyGroup>
+ <OctopusContextIsReleaseBuild Condition="'$(OctopusPackageConfiguration)' == '$(Configuration)' Or '$(WebProjectOutputDir)' == ''">True</OctopusContextIsReleaseBuild>
+ <OctopusContextIsWebApplication Condition="Exists('$(OctopusWebConfigFile)')">True</OctopusContextIsWebApplication>
+ </PropertyGroup>
+
+ <Message Text="IsReleaseBuild: $(OctopusContextIsReleaseBuild)" />
+ <Message Text="IsWebApp: $(OctopusContextIsWebApplication)" />
+ <Message Text="This is not a $(OctopusPackageConfiguration) build, so any Octopus packaging will be skipped" Importance="High" Condition="'$(OctopusContextIsReleaseBuild)' != 'True'" />
+ <Message Text="This is a $(OctopusPackageConfiguration) build of a web application, so an Octopus package will be created" Importance="High" Condition="'$(OctopusContextIsReleaseBuild)' == 'True' And '$(OctopusContextIsWebApplication)' == 'True'" />
+ <Message Text="This is a $(OctopusPackageConfiguration) build of an executable, so an Octopus package will be created" Importance="High" Condition="'$(OctopusContextIsReleaseBuild)' == 'True' And '$(OctopusContextIsWebApplication)' != 'True'" />
+
+ <CallTarget Targets="OctopusPackageWeb" Condition="'$(OctopusContextIsReleaseBuild)' == 'True' And '$(OctopusContextIsWebApplication)' == 'True'" />
+ <CallTarget Targets="OctopusPackageApp" Condition="'$(OctopusContextIsReleaseBuild)' == 'True' And '$(OctopusContextIsWebApplication)' != 'True'" />
+ </Target>
+
+ <!--
+ Find NuGet.exe and the project NuSpec
+ -->
+ <Target Name="OctopusFindNuGetSettings">
+ <Error
+ Code="OCTO: 1001"
+ Text="OctoPack: Expected to find a NuGet spec file named $(OctopusNuSpecFileName) 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 OctopusNuSpecFileName in your project."
+ Condition="!Exists('$(OctopusNuSpecFileName)')"
+ />
+
+ <ItemGroup>
+ <NuGetExeFinder Include="$(OctopusNuGetExePath)" />
+ </ItemGroup>
+
+ <PropertyGroup>
+ <NuGetExe>@(NuGetExeFinder, ';')</NuGetExe>
+ </PropertyGroup>
+
+ <Error
+ Code="OCTO: 1002"
+ Text="OctoPack: Could not locate NuGet.exe. Please add a NuGet package reference for NuGet.CommandLine, or set the property OctopusNuGetExePath in your project. Current search path is: $(NuGetExe)"
+ Condition="!Exists('$(NuGetExe)')"
+ />
+
+ <Message Importance="High" Text="NuGet.exe found: $(NuGetExe)"/>
+ </Target>
+
+ <!--
+ Packaging Web Applications
+ -->
+ <Target Name="OctopusPackageWeb" DependsOnTargets="$(OnBefore_CopyWebApplicationDefault);OctopusFindNuGetSettings">
+ <Message Text="Project was published to: $(OutDir)" />
+ <Copy SourceFiles="$(OctopusNuSpecFileName)" DestinationFolder="$(WebProjectOutputDir)" />
+
+ <Exec Command='"$(NuGetExe)" pack "$(WebProjectOutputDir.TrimEnd(&quot;\&quot;))\$(OctopusNuSpecFileName)" -OutputDirectory "$(OutputPath.TrimEnd(&quot;\&quot;))" -basePath "$(WebProjectOutputDir.TrimEnd(&quot;\&quot;))" -Version "$(OctopusPackageVersion)" -NoPackageAnalysis' />
+ </Target>
+
+ <!--
+ Packaging windows services and console applications
+ -->
+ <Target Name="OctopusPackageApp" DependsOnTargets="OctopusFindNuGetSettings">
+ <RemoveDir Directories="$(OctopusTemporaryDirectory)" ContinueOnError="true" />
+ <MakeDir Directories="$(OctopusTemporaryDirectory)" />
+
+ <ItemGroup>
+ <ContentToPackage Include="$(OutputPath)\**\*" Exclude="$(OutputPath)\**\*.vshost.*;$(OutputPath)\**\*.nupkg" />
+ </ItemGroup>
+ <Copy
+ SourceFiles="@(ContentToPackage)"
+ DestinationFiles="@(ContentToPackage->'$(OctopusTemporaryDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"
+ />
+
+ <Copy SourceFiles="$(OctopusNuSpecFileName)" DestinationFolder="$(OctopusTemporaryDirectory)" />
+
+ <Exec Command='"$(NuGetExe)" pack "$(OctopusNuSpecFileName)" -OutputDirectory "$(OutputPath.TrimEnd(&quot;\&quot;))" -basePath "$(OctopusTemporaryDirectory)" -Version "$(OctopusPackageVersion)" -NoPackageAnalysis' />
+ </Target>
+</Project>
@@ -0,0 +1,73 @@
+param($installPath, $toolsPath, $package, $project)
+
+Import-Module (Join-Path $toolsPath "MSBuild.psm1")
+
+function Delete-Temporary-File
+{
+ Write-Host "Delete temporary file"
+
+ $project.ProjectItems | Where-Object { $_.Name -eq 'OctoPack-Readme.txt' } | Foreach-Object {
+ Remove-Item ( $_.FileNames(0) )
+ $_.Remove()
+ }
+}
+
+function Get-RelativePath ( $folder, $filePath )
+{
+ Write-Verbose "Resolving paths relative to '$Folder'"
+ $from = $Folder = split-path $Folder -NoQualifier -Resolve:$Resolve
+ $to = $filePath = split-path $filePath -NoQualifier -Resolve:$Resolve
+
+ while($from -and $to -and ($from -ne $to)) {
+ if($from.Length -gt $to.Length) {
+ $from = split-path $from
+ } else {
+ $to = split-path $to
+ }
+ }
+
+ $filepath = $filepath -replace "^"+[regex]::Escape($to)+"\\"
+ $from = $Folder
+ while($from -and $to -and $from -gt $to ) {
+ $from = split-path $from
+ $filepath = join-path ".." $filepath
+ }
+ Write-Output $filepath
+}
+
+function Install-Targets ( $project )
+{
+ Write-Host ("Installing OctoPack Targets file import into project " + $project.Name)
+
+ $buildProject = Get-MSBuildProject
+
+ $buildProject.Xml.Imports | Where-Object { $_.Project -match "OctoPack" } | foreach-object {
+ Write-Host ("Removing old import: " + $_.Project)
+ $buildProject.Xml.RemoveChild($_)
+ }
+
+ $projectItem = Get-ChildItem $project.FullName
+ Write-Host ("The current project is: " + $project.FullName)
+ Write-Host ("Project parent directory: " + $projectItem.Directory)
+
+ $importFile = Join-Path $toolsPath "..\targets\OctoPack.targets"
+ $importFile = Resolve-Path $importFile
+ $importFile = Get-RelativePath $projectItem.Directory $importFile
+
+ Write-Host ("Import will be added for: " + $importFile)
+
+ $target = $buildProject.Xml.AddImport( $importFile )
+
+ $project.Save()
+
+ Write-Host ("Import added!")
+}
+
+function Main
+{
+ Delete-Temporary-File
+
+ Install-Targets $project
+}
+
+Main
Oops, something went wrong.

0 comments on commit 9c9bf63

Please sign in to comment.