Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial add

  • Loading branch information...
commit 9c9bf63f6052784e26300de40e1c6802d718eafb 0 parents
Paul Stovell PaulStovell authored
56 .gitignore
... ... @@ -0,0 +1,56 @@
  1 +*.*scc
  2 +*.FileListAbsolute.txt
  3 +*.aps
  4 +*.bak
  5 +*.[Cc]ache
  6 +*.clw
  7 +*.eto
  8 +*.exe
  9 +*.fb6lck
  10 +*.fbl6
  11 +*.fbpInf
  12 +*.ilk
  13 +*.lib
  14 +*.log
  15 +*.ncb
  16 +*.nlb
  17 +*.obj
  18 +*.patch
  19 +*.pch
  20 +*.pdb
  21 +*.plg
  22 +*.[Pp]ublish.xml
  23 +*.rdl.data
  24 +*.sbr
  25 +*.scc
  26 +*.sig
  27 +*.sqlsuo
  28 +*.suo
  29 +*.svclog
  30 +*.tlb
  31 +*.tlh
  32 +*.tli
  33 +*.tmp
  34 +*.user
  35 +*.vshost.*
  36 +*DXCore.Solution
  37 +*_i.c
  38 +*_p.c
  39 +Ankh.Load
  40 +Backup*
  41 +CVS/
  42 +PrecompiledWeb/
  43 +UpgradeLog*.*
  44 +[Bb]in/
  45 +[Dd]ebug/
  46 +[Oo]bj/
  47 +[Rr]elease/
  48 +[Tt]humbs.db
  49 +_UpgradeReport_Files
  50 +_[Rr]e[Ss]harper.*/
  51 +hgignore[.-]*
  52 +ignore[.-]*
  53 +svnignore[.-]*
  54 +lint.db
  55 +build
  56 +tools/TestResult.xml
9 build.ps1
... ... @@ -0,0 +1,9 @@
  1 +$Version = 1
  2 +
  3 +do {
  4 + $Version = $Version + 1
  5 +} while ( Test-Path (".\build\OctoPack.1.0." + $Version + ".nupkg" ) )
  6 +
  7 +.\tools\NuGet.exe pack source\OctoPack.nuspec -OutputDirectory build -Version ("1.0." + $Version) -BasePath source
  8 +
  9 +# .\tools\NuGet.exe push (".\build\OctoPack.1.0." + $Version + ".nupkg") "31f41c07-78c7-4f87-adb4-b3bd8aabb992"
26 source/OctoPack.nuspec
... ... @@ -0,0 +1,26 @@
  1 +<?xml version="1.0"?>
  2 +<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  3 + <metadata>
  4 + <version>1.0.0</version>
  5 + <authors>Octopus Deploy</authors>
  6 + <owners>Octopus Deploy</owners>
  7 + <licenseUrl>http://octopusdeploy.com/</licenseUrl>
  8 + <projectUrl>http://octopusdeploy.com/</projectUrl>
  9 + <id>OctoPack</id>
  10 + <requireLicenseAcceptance>false</requireLicenseAcceptance>
  11 + <description>
  12 + Octopus is an automated deployment tool powered by NuGet (octopusdeploy.com). This tool adds a post-build activity to your Visual Studio project,
  13 + so that an Octopus-compatible NuGet package is produced in the Bin directory whenever a Release build completes.
  14 + </description>
  15 + <dependencies>
  16 + <dependency id="NuGet.CommandLine" version="1.6.0" />
  17 + </dependencies>
  18 + </metadata>
  19 +
  20 + <files>
  21 + <file src="content\OctoPack-Readme.txt" target="content\OctoPack-Readme.txt" />
  22 + <file src="tools\Install.ps1" target="tools\Install.ps1" />
  23 + <file src="tools\MSBuild.psm1" target="tools\MSBuild.psm1" />
  24 + <file src="targets\OctoPack.targets" target="targets\OctoPack.targets" />
  25 + </files>
  26 +</package>
3  source/content/OctoPack-Readme.txt
... ... @@ -0,0 +1,3 @@
  1 +OctoPack has to create this file, because NuGet will only run the custom
  2 +Install.ps1 script if a content file exists. The Install.ps1 should have
  3 +removed this file, but since it hasn't, please delete it manually.
106 source/targets/OctoPack.targets
... ... @@ -0,0 +1,106 @@
  1 +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  2 + <PropertyGroup>
  3 + <BuildDependsOn>
  4 + $(BuildDependsOn);
  5 + OctopusEstablishContext
  6 + </BuildDependsOn>
  7 + </PropertyGroup>
  8 +
  9 + <PropertyGroup>
  10 + <_CopyWebApplicationDependsOn>
  11 + $(_CopyWebApplicationDependsOn);
  12 + OctopusEstablishContext
  13 + </_CopyWebApplicationDependsOn>
  14 + </PropertyGroup>
  15 +
  16 + <!--
  17 + Configuration properties - you can override these from the command line
  18 + -->
  19 + <PropertyGroup>
  20 + <OctopusProjectRoot Condition="'$(OctopusProjectRoot)' == ''">$(MSBuildProjectDirectory.TrimEnd('\'))</OctopusProjectRoot>
  21 + <OctopusPackageConfiguration Condition="'$(OctopusPackageConfiguration)' == ''">Release</OctopusPackageConfiguration>
  22 + <OctopusNuSpecFileName Condition="'$(OctopusNuSpecFileName)' == ''">$(MSBuildProjectFullPath)</OctopusNuSpecFileName>
  23 + <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>
  24 + <OctopusTemporaryDirectory Condition="'$(OctopusTemporaryDirectory)' == ''">$(OutputPath.TrimEnd('\'))\NuGet-temp</OctopusTemporaryDirectory>
  25 + <OctopusPackageVersion Condition="'$(OctopusPackageVersion)' == ''">1.0.0</OctopusPackageVersion>
  26 + <OctopusWebConfigFile Condition="'$(OctopusWebConfigFile)' == ''">$(OctopusProjectRoot)\Web.config</OctopusWebConfigFile>
  27 + </PropertyGroup>
  28 +
  29 + <!--
  30 + Establsh Context
  31 + This target figures out whether this is a web project or normal application, and whether it is being built in release mode.
  32 + It then discovers the location of NuGet.exe.
  33 + -->
  34 + <Target Name="OctopusEstablishContext">
  35 + <PropertyGroup>
  36 + <OctopusContextIsReleaseBuild Condition="'$(OctopusPackageConfiguration)' == '$(Configuration)' Or '$(WebProjectOutputDir)' == ''">True</OctopusContextIsReleaseBuild>
  37 + <OctopusContextIsWebApplication Condition="Exists('$(OctopusWebConfigFile)')">True</OctopusContextIsWebApplication>
  38 + </PropertyGroup>
  39 +
  40 + <Message Text="IsReleaseBuild: $(OctopusContextIsReleaseBuild)" />
  41 + <Message Text="IsWebApp: $(OctopusContextIsWebApplication)" />
  42 + <Message Text="This is not a $(OctopusPackageConfiguration) build, so any Octopus packaging will be skipped" Importance="High" Condition="'$(OctopusContextIsReleaseBuild)' != 'True'" />
  43 + <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'" />
  44 + <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'" />
  45 +
  46 + <CallTarget Targets="OctopusPackageWeb" Condition="'$(OctopusContextIsReleaseBuild)' == 'True' And '$(OctopusContextIsWebApplication)' == 'True'" />
  47 + <CallTarget Targets="OctopusPackageApp" Condition="'$(OctopusContextIsReleaseBuild)' == 'True' And '$(OctopusContextIsWebApplication)' != 'True'" />
  48 + </Target>
  49 +
  50 + <!--
  51 + Find NuGet.exe and the project NuSpec
  52 + -->
  53 + <Target Name="OctopusFindNuGetSettings">
  54 + <Error
  55 + Code="OCTO: 1001"
  56 + 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."
  57 + Condition="!Exists('$(OctopusNuSpecFileName)')"
  58 + />
  59 +
  60 + <ItemGroup>
  61 + <NuGetExeFinder Include="$(OctopusNuGetExePath)" />
  62 + </ItemGroup>
  63 +
  64 + <PropertyGroup>
  65 + <NuGetExe>@(NuGetExeFinder, ';')</NuGetExe>
  66 + </PropertyGroup>
  67 +
  68 + <Error
  69 + Code="OCTO: 1002"
  70 + 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)"
  71 + Condition="!Exists('$(NuGetExe)')"
  72 + />
  73 +
  74 + <Message Importance="High" Text="NuGet.exe found: $(NuGetExe)"/>
  75 + </Target>
  76 +
  77 + <!--
  78 + Packaging Web Applications
  79 + -->
  80 + <Target Name="OctopusPackageWeb" DependsOnTargets="$(OnBefore_CopyWebApplicationDefault);OctopusFindNuGetSettings">
  81 + <Message Text="Project was published to: $(OutDir)" />
  82 + <Copy SourceFiles="$(OctopusNuSpecFileName)" DestinationFolder="$(WebProjectOutputDir)" />
  83 +
  84 + <Exec Command='"$(NuGetExe)" pack "$(WebProjectOutputDir.TrimEnd(&quot;\&quot;))\$(OctopusNuSpecFileName)" -OutputDirectory "$(OutputPath.TrimEnd(&quot;\&quot;))" -basePath "$(WebProjectOutputDir.TrimEnd(&quot;\&quot;))" -Version "$(OctopusPackageVersion)" -NoPackageAnalysis' />
  85 + </Target>
  86 +
  87 + <!--
  88 + Packaging windows services and console applications
  89 + -->
  90 + <Target Name="OctopusPackageApp" DependsOnTargets="OctopusFindNuGetSettings">
  91 + <RemoveDir Directories="$(OctopusTemporaryDirectory)" ContinueOnError="true" />
  92 + <MakeDir Directories="$(OctopusTemporaryDirectory)" />
  93 +
  94 + <ItemGroup>
  95 + <ContentToPackage Include="$(OutputPath)\**\*" Exclude="$(OutputPath)\**\*.vshost.*;$(OutputPath)\**\*.nupkg" />
  96 + </ItemGroup>
  97 + <Copy
  98 + SourceFiles="@(ContentToPackage)"
  99 + DestinationFiles="@(ContentToPackage->'$(OctopusTemporaryDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"
  100 + />
  101 +
  102 + <Copy SourceFiles="$(OctopusNuSpecFileName)" DestinationFolder="$(OctopusTemporaryDirectory)" />
  103 +
  104 + <Exec Command='"$(NuGetExe)" pack "$(OctopusNuSpecFileName)" -OutputDirectory "$(OutputPath.TrimEnd(&quot;\&quot;))" -basePath "$(OctopusTemporaryDirectory)" -Version "$(OctopusPackageVersion)" -NoPackageAnalysis' />
  105 + </Target>
  106 +</Project>
73 source/tools/Install.ps1
... ... @@ -0,0 +1,73 @@
  1 +param($installPath, $toolsPath, $package, $project)
  2 +
  3 +Import-Module (Join-Path $toolsPath "MSBuild.psm1")
  4 +
  5 +function Delete-Temporary-File
  6 +{
  7 + Write-Host "Delete temporary file"
  8 +
  9 + $project.ProjectItems | Where-Object { $_.Name -eq 'OctoPack-Readme.txt' } | Foreach-Object {
  10 + Remove-Item ( $_.FileNames(0) )
  11 + $_.Remove()
  12 + }
  13 +}
  14 +
  15 +function Get-RelativePath ( $folder, $filePath )
  16 +{
  17 + Write-Verbose "Resolving paths relative to '$Folder'"
  18 + $from = $Folder = split-path $Folder -NoQualifier -Resolve:$Resolve
  19 + $to = $filePath = split-path $filePath -NoQualifier -Resolve:$Resolve
  20 +
  21 + while($from -and $to -and ($from -ne $to)) {
  22 + if($from.Length -gt $to.Length) {
  23 + $from = split-path $from
  24 + } else {
  25 + $to = split-path $to
  26 + }
  27 + }
  28 +
  29 + $filepath = $filepath -replace "^"+[regex]::Escape($to)+"\\"
  30 + $from = $Folder
  31 + while($from -and $to -and $from -gt $to ) {
  32 + $from = split-path $from
  33 + $filepath = join-path ".." $filepath
  34 + }
  35 + Write-Output $filepath
  36 +}
  37 +
  38 +function Install-Targets ( $project )
  39 +{
  40 + Write-Host ("Installing OctoPack Targets file import into project " + $project.Name)
  41 +
  42 + $buildProject = Get-MSBuildProject
  43 +
  44 + $buildProject.Xml.Imports | Where-Object { $_.Project -match "OctoPack" } | foreach-object {
  45 + Write-Host ("Removing old import: " + $_.Project)
  46 + $buildProject.Xml.RemoveChild($_)
  47 + }
  48 +
  49 + $projectItem = Get-ChildItem $project.FullName
  50 + Write-Host ("The current project is: " + $project.FullName)
  51 + Write-Host ("Project parent directory: " + $projectItem.Directory)
  52 +
  53 + $importFile = Join-Path $toolsPath "..\targets\OctoPack.targets"
  54 + $importFile = Resolve-Path $importFile
  55 + $importFile = Get-RelativePath $projectItem.Directory $importFile
  56 +
  57 + Write-Host ("Import will be added for: " + $importFile)
  58 +
  59 + $target = $buildProject.Xml.AddImport( $importFile )
  60 +
  61 + $project.Save()
  62 +
  63 + Write-Host ("Import added!")
  64 +}
  65 +
  66 +function Main
  67 +{
  68 + Delete-Temporary-File
  69 +
  70 + Install-Targets $project
  71 +}
  72 +
  73 +Main
121 source/tools/MSBuild.psm1
... ... @@ -0,0 +1,121 @@
  1 +function Resolve-ProjectName {
  2 + param(
  3 + [parameter(ValueFromPipelineByPropertyName = $true)]
  4 + [string[]]$ProjectName
  5 + )
  6 +
  7 + if($ProjectName) {
  8 + $projects = Get-Project $ProjectName
  9 + }
  10 + else {
  11 + # All projects by default
  12 + $projects = Get-Project
  13 + }
  14 +
  15 + $projects
  16 +}
  17 +
  18 +function Get-MSBuildProject {
  19 + param(
  20 + [parameter(ValueFromPipelineByPropertyName = $true)]
  21 + [string[]]$ProjectName
  22 + )
  23 + Process {
  24 + (Resolve-ProjectName $ProjectName) | % {
  25 + $path = $_.FullName
  26 + @([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($path))[0]
  27 + }
  28 + }
  29 +}
  30 +
  31 +function Add-Import {
  32 + param(
  33 + [parameter(Position = 0, Mandatory = $true)]
  34 + [string]$Path,
  35 + [parameter(Position = 1, ValueFromPipelineByPropertyName = $true)]
  36 + [string[]]$ProjectName
  37 + )
  38 + Process {
  39 + (Resolve-ProjectName $ProjectName) | %{
  40 + $buildProject = $_ | Get-MSBuildProject
  41 + $buildProject.Xml.AddImport($Path)
  42 + $_.Save()
  43 + }
  44 + }
  45 +}
  46 +
  47 +function Set-MSBuildProperty {
  48 + param(
  49 + [parameter(Position = 0, Mandatory = $true)]
  50 + $PropertyName,
  51 + [parameter(Position = 1, Mandatory = $true)]
  52 + $PropertyValue,
  53 + [parameter(Position = 2, ValueFromPipelineByPropertyName = $true)]
  54 + [string[]]$ProjectName
  55 + )
  56 + Process {
  57 + (Resolve-ProjectName $ProjectName) | %{
  58 + $buildProject = $_ | Get-MSBuildProject
  59 + $buildProject.SetProperty($PropertyName, $PropertyValue) | Out-Null
  60 + $_.Save()
  61 + }
  62 + }
  63 +}
  64 +
  65 +function Get-MSBuildProperty {
  66 + param(
  67 + [parameter(Position = 0, Mandatory = $true)]
  68 + $PropertyName,
  69 + [parameter(Position = 2, ValueFromPipelineByPropertyName = $true)]
  70 + [string]$ProjectName
  71 + )
  72 +
  73 + $buildProject = Get-MSBuildProject $ProjectName
  74 + $buildProject.GetProperty($PropertyName)
  75 +}
  76 +
  77 +function Add-SolutionDirProperty {
  78 + param(
  79 + [parameter(ValueFromPipelineByPropertyName = $true)]
  80 + [string[]]$ProjectName
  81 + )
  82 +
  83 + (Resolve-ProjectName $ProjectName) | %{
  84 + $buildProject = $_ | Get-MSBuildProject
  85 +
  86 + if(!($buildProject.Xml.Properties | ?{ $_.Name -eq 'SolutionDir' })) {
  87 + # Get the relative path to the solution
  88 + $relativeSolutionPath = [NuGet.PathUtility]::GetRelativePath($_.FullName, $dte.Solution.Properties.Item("Path").Value)
  89 + $relativeSolutionPath = [IO.Path]::GetDirectoryName($relativeSolutionPath)
  90 + $relativeSolutionPath = [NuGet.PathUtility]::EnsureTrailingSlash($relativeSolutionPath)
  91 +
  92 + $solutionDirProperty = $buildProject.Xml.AddProperty("SolutionDir", $relativeSolutionPath)
  93 + $solutionDirProperty.Condition = '$(SolutionDir) == '''' Or $(SolutionDir) == ''*Undefined*'''
  94 + $_.Save()
  95 + }
  96 + }
  97 +}
  98 +
  99 +
  100 +'Set-MSBuildProperty', 'Add-SolutionDirProperty', 'Add-Import','Add-SolutionDirProperty' | %{
  101 + Register-TabExpansion $_ @{
  102 + ProjectName = { Get-Project -All | Select -ExpandProperty Name }
  103 + }
  104 +}
  105 +
  106 +Register-TabExpansion 'Get-MSBuildProperty' @{
  107 + ProjectName = { Get-Project -All | Select -ExpandProperty Name }
  108 + PropertyName = {param($context)
  109 + if($context.ProjectName) {
  110 + $buildProject = Get-MSBuildProject $context.ProjectName
  111 + }
  112 +
  113 + if(!$buildProject) {
  114 + $buildProject = Get-MSBuildProject
  115 + }
  116 +
  117 + $buildProject.Xml.Properties | Sort Name | Select -ExpandProperty Name -Unique
  118 + }
  119 +}
  120 +
  121 +Export-ModuleMember Get-MSBuildProject, Add-SolutionDirProperty, Add-Import, Get-MSBuildProperty, Set-MSBuildProperty

0 comments on commit 9c9bf63

Please sign in to comment.
Something went wrong with that request. Please try again.