Created
June 29, 2012 19:01
-
-
Save andrebires/3019987 to your computer and use it in GitHub Desktop.
Octopus Deploy OctoPack.targets file that gets the assembly version to create the deploy package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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)' == ''">$(MSBuildProjectName.Replace('.csproj', '').Replace('.vbproj', '')).nuspec</OctopusNuSpecFileName> | |
<OctopusTemporaryDirectory Condition="'$(OctopusTemporaryDirectory)' == ''">$(OutputPath.TrimEnd('\'))\NuGet-temp</OctopusTemporaryDirectory> | |
<OctopusPackageVersion Condition="'$(OctopusPackageVersion)' == ''">1.0.0</OctopusPackageVersion> | |
<OctopusWebConfigFile Condition="'$(OctopusWebConfigFile)' == ''">$(OctopusProjectRoot)\Web.config</OctopusWebConfigFile> | |
<OctopusOutputDirectory Condition="'$(OctopusOutputDirectory)' == ''">$(OutputPath)</OctopusOutputDirectory> | |
</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'" /> | |
<Message Text="OctopusProjectRoot: $(OctopusProjectRoot)" /> | |
<Message Text="OctopusNuGetExePath: $(OctopusNuGetExePath)" /> | |
<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> | |
<FindNuGet Include="$(OctopusNuGetExePath)" /> | |
<FindNuGet Include="$(MSBuildThisFileDirectory)..\tools\NuGet.exe" /> | |
<FindNuGet Include="$(OctopusProjectRoot)\packages\OctoPack*\tools\NuGet.exe" /> | |
<FindNuGet Include="$(OctopusProjectRoot)\.nuget\NuGet*.exe" /> | |
<FindNuGet Include="$(OctopusProjectRoot)\..\packages\OctoPack*\tools\NuGet.exe" /> | |
<FindNuGet Include="$(OctopusProjectRoot)\..\.nuget\NuGet*.exe" /> | |
<FindNuGet Include="$(OctopusProjectRoot)\..\..\packages\OctoPack*\tools\NuGet.exe" /> | |
<FindNuGet Include="$(OctopusProjectRoot)\..\..\.nuget\NuGet*.exe" /> | |
</ItemGroup> | |
<PropertyGroup> | |
<NuGetExe Condition="'$(OctopusNuGetExePath)' == ''">%(FindNuGet.Identity)</NuGetExe> | |
<NuGetExe Condition="'$(OctopusNuGetExePath)' != ''">$(OctopusNuGetExePath)</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)" /> | |
<MakeDir Directories="$(OctopusOutputDirectory.TrimEnd("\"))"/> | |
<GetAssemblyIdentity | |
AssemblyFiles="$(WebProjectOutputDir)\bin\$(MSBuildProjectName.Replace('.csproj', '').Replace('.vbproj', '')).dll"> | |
<Output | |
TaskParameter="Assemblies" | |
ItemName="AssemblyIdentities"/> | |
</GetAssemblyIdentity> | |
<Exec Command='"$(NuGetExe)" pack "$(WebProjectOutputDir.TrimEnd("\"))\$(OctopusNuSpecFileName)" -OutputDirectory "$(OctopusOutputDirectory.TrimEnd("\"))" -basePath "$(WebProjectOutputDir.TrimEnd("\"))" -Version "%(AssemblyIdentities.Version)" -NoPackageAnalysis' /> | |
<ItemGroup> | |
<PackagesBuilt Include="$(OctopusOutputDirectory.TrimEnd("\"))\*.nupkg" /> | |
</ItemGroup> | |
<Message Importance="High" Text="Copy packages: @(PackagesBuilt) to $(OutDir)"/> | |
<Copy SourceFiles="@(PackagesBuilt)" DestinationFolder="$(OutDir)" /> | |
</Target> | |
<!-- | |
Packaging windows services and console applications | |
--> | |
<Target Name="OctopusPackageApp" DependsOnTargets="OctopusFindNuGetSettings"> | |
<RemoveDir Directories="$(OctopusTemporaryDirectory)" ContinueOnError="true" /> | |
<MakeDir Directories="$(OctopusTemporaryDirectory)" /> | |
<Message Text="Files version: %(AssemblyIdentities.Version)"/> | |
<ItemGroup> | |
<ContentToPackage Include="$(OutputPath)\**\*" Exclude="*.nupkg" /> | |
<ContentToPackage Include="$(OutDir)\**\*" Exclude="*.nupkg" /> | |
</ItemGroup> | |
<Copy SourceFiles="@(ContentToPackage)" | |
DestinationFiles="@(ContentToPackage->'$(OctopusTemporaryDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" | |
/> | |
<Copy SourceFiles="$(OctopusNuSpecFileName)" DestinationFolder="$(OctopusTemporaryDirectory)" /> | |
<MakeDir Directories="$(OctopusOutputDirectory.TrimEnd("\"))"/> | |
<GetAssemblyIdentity | |
AssemblyFiles="$(OctopusTemporaryDirectory)\$(MSBuildProjectName.Replace('.csproj', '').Replace('.vbproj', '')).exe"> | |
<Output | |
TaskParameter="Assemblies" | |
ItemName="AssemblyIdentities"/> | |
</GetAssemblyIdentity> | |
<Exec Command='"$(NuGetExe)" pack "$(OctopusTemporaryDirectory)\$(OctopusNuSpecFileName)" -OutputDirectory "$(OctopusOutputDirectory.TrimEnd("\"))" -basePath "$(OctopusTemporaryDirectory)" -Version "%(AssemblyIdentities.Version)" -NoPackageAnalysis' /> | |
<ItemGroup> | |
<PackagesBuilt Include="$(OctopusOutputDirectory.TrimEnd("\"))\*.nupkg" /> | |
</ItemGroup> | |
<Message Importance="High" Text="Copy packages: @(PackagesBuilt) to $(OutDir)"/> | |
<Copy SourceFiles="@(PackagesBuilt)" DestinationFolder="$(OutDir)" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment