Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Loránd Biró committed Jun 12, 2016
0 parents commit 8c300b9
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Source/Build/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Loránd Biró

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# OctoPack Precompile

This NuGet package adds an ASP.NET precompile step to the build just before (and only if) OctoPack is called. All the files - which would be packaged by OctoPack - will be copied into an intermediate folder. The ASP.NET compiler will be executed on this intermediate folder creating the precompiled website to be packaged. This target doesn't tell OctoPack where are these files so a nuspec file is needed to specify the location of the precompiled website.

I created this to enable ASP.NET precompile in a simple TeamCity-Octopus pipeline. I didn't want to put publish profiles or any complex MSBuild 'magic' into the repository just to enable a feature that should be a simple checkbox, so I created this NuGet package to hide the complexity.

I tested it only with TeamCity Visual Studio build runner (VS2015) with Octopus plugin, but I'm sure there are some more complex scenarios where this simple build step is not enough.

## How to use
1. Install the `OctoPack.Precompile` NuGet package into the project you want to precompile on packaging.
2. Create a nuspec file for OctoPack or modify it if you already have to include the files in `obj/Precompiled`. The nuspec file should be in the same directory as your project file matching its name. For example if your project file is `YourProject.csproj`, the nuspec file should be `YourProject.nuspec`. Here's a minimal example:

```XML
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>YourProject</id>
<authors>YourProject</authors>
<description>YourProject</description>
<version>1.0.0</version>
</metadata>
<files>
<file src="obj\Precompiled\**\*.*" target="" />
</files>
</package>
```

> Visit http://docs.octopusdeploy.com/display/OD/Using+OctoPack or http://docs.nuget.org/create/nuspec-reference for more information.
That's it. Next time TeamCity or another build tool invokes OctoPack, precompilation will kick in and your deploy package will contain a precompiled website.
11 changes: 11 additions & 0 deletions Source/Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (-not (Test-Path "Build"))
{
New-Item "Build" -ItemType "Directory"
}

if (-not (Test-Path "Build\NuGet.exe"))
{
Invoke-WebRequest "https://nuget.org/nuget.exe" -OutFile "Build\NuGet.exe"
}

&Build\NuGet.exe pack "OctoPack.Precompile.nuspec" -OutputDirectory "Build"
20 changes: 20 additions & 0 deletions Source/OctoPack.Precompile.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>OctoPack.Precompile</id>
<version>1.0.0</version>
<title>OctoPack.Precompile</title>
<authors>Loránd Biró</authors>
<owners>Loránd Biró</owners>
<licenseUrl>https://github.com/LorandBiro/OctoPack.Precompile/raw/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/LorandBiro/OctoPack.Precompile</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<developmentDependency>true</developmentDependency>
<description>This package adds an ASP.NET precompile step to the build just before (and only if) OctoPack is called. Change your nuspec file to include the precompiled files and next time when TeamCity or another build tool invokes OctoPack, precompilation will kick in and your deploy package will contain a precompiled website. Visit the project site for more detailed instructions.</description>
<summary>ASP.NET precompile build step for OctoPack.</summary>
<tags>octopus octopack asp.net website precompile</tags>
</metadata>
<files>
<file src="OctoPack.Precompile.targets" target="build" />
</files>
</package>
33 changes: 33 additions & 0 deletions Source/OctoPack.Precompile.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PrecompiledIntermediateFolder Condition="'$(PrecompiledIntermediateFolder)'==''">obj\PrecompiledIntermediate</PrecompiledIntermediateFolder>
<PrecompiledFolder Condition="'$(PrecompiledFolder)'==''">obj\Precompiled</PrecompiledFolder>
</PropertyGroup>

<Target Name="Precompile" BeforeTargets="OctoPack" Condition="$(RunOctoPack)">
<ItemGroup>
<!-- This should collect the files the same way OctoPack does. https://github.com/OctopusDeploy/OctoPack -->
<CollectedFiles Include="@(FileWrites)" Exclude="$(IntermediateOutputPath)**\*" />
<CollectedFiles Include="@(FileWritesShareable)" Exclude="$(IntermediateOutputPath)**\*" />
<CollectedFiles Include="@(Content)" />

<!--
Some of the collected file paths are full paths, but we need paths relative to the project so we can perform a recursive copy.
Also it looks like NuGet doesn't like the packages.config inside the packages, so we skip it.
http://help.octopusdeploy.com/discussions/problems/29208-packagesconfig-files-are-excluded-from-packages-created-by-octopack
-->
<NormalizedFiles Include="@(CollectedFiles->'%(FullPath)'->Substring($(ProjectDir.Length)))" Exclude="packages.config" />
</ItemGroup>

<!-- It's important to clear the output folder, so the nuspec file can include the whole folder. -->
<RemoveDir Directories="$(PrecompiledIntermediateFolder);$(PrecompiledFolder)" />

<Copy SourceFiles="@(NormalizedFiles)"
DestinationFiles="@(NormalizedFiles->'$(PrecompiledIntermediateFolder)\%(Identity)')" />

<AspNetCompiler PhysicalPath="$(ProjectDir)$(PrecompiledIntermediateFolder)"
TargetPath="$(ProjectDir)$(PrecompiledFolder)"
VirtualPath="/" />
</Target>
</Project>

0 comments on commit 8c300b9

Please sign in to comment.