Skip to content

Instantly share code, notes, and snippets.

@owickstrom
Created October 17, 2012 07:52
Show Gist options
  • Save owickstrom/3904274 to your computer and use it in GitHub Desktop.
Save owickstrom/3904274 to your computer and use it in GitHub Desktop.
A simple Continuous Integration and Deployment workflow with ASP.NET MVC, GitHub and Jenkins
# Ignore dot-files, except the .gitignore file.
.*
!.gitignore
# (All rules from CSharp.gitignore)
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Import MSBuildExtensionsPack -->
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<!-- Names of all projects -->
<PropertyGroup>
<MyApp>MyApp</MyApp>
<MyAppTests>MyApp.Tests</MyAppTests>
<Configuration Condition="$(Configuration) == ''">Release</Configuration>
<PublishProfile Condition="$(PublishProfile) == ''">Test</PublishProfile>
<OutputDir>.out</OutputDir>
<NUnitConsole>packages\NUnit.Runners.2.6.1\tools\nunit-console.exe</NUnitConsole>
</PropertyGroup>
<ItemGroup>
<!-- All projects -->
<Projects Include="$(MyApp)" />
<!-- Test projects -->
<TestProjects Include="$(MyAppTests)" />
</ItemGroup>
<Target Name="CreateDirectories">
<MakeDir Directories="$(OutputDir)"/>
<MakeDir Directories="$(OutputDir)\Package"/>
<MakeDir Directories="$(MyApp)\obj\Package"/>
</Target>
<Target Name="Clean" DependsOnTargets="CreateDirectories">
<MSBuild.ExtensionPack.FileSystem.Folder
TaskAction="RemoveContent"
Path="$(OutputDir)"/>
<MSBuild.ExtensionPack.FileSystem.Folder
TaskAction="RemoveContent"
Path="$(MyApp)\obj\Package"/>
</Target>
<!-- Compiles and Cleans all projects (if named correctly) -->
<Target Name="Build" DependsOnTargets="Clean">
<PropertyGroup>
<CurrentProject>%(Projects.Identity)</CurrentProject>
</PropertyGroup>
<MSBuild Projects="$(CurrentProject)\$(CurrentProject).csproj"
Targets="Clean;Build"
Properties="Configuration=$(Configuration)" />
</Target>
<!-- Run NUnit Tests -->
<Target Name="Test" DependsOnTargets="Build">
<PropertyGroup>
<CurrentProject>%(TestProjects.Identity)</CurrentProject>
</PropertyGroup>
<MSBuild Projects="$(CurrentProject)\$(CurrentProject).csproj"
Targets="Build"
Properties="Configuration=$(Configuration)" />
<CreateItem Include="$(CurrentProject)\bin\$(Configuration)\$(CurrentProject).dll">
<Output TaskParameter="Include" ItemName="TestAssembly" />
</CreateItem>
<PropertyGroup>
<NUNitOptions>/result="$(OutputDir)\$(CurrentProject).Results.xml"</NUNitOptions>
<NUNitCommand>$(NUnitConsole) $(NUNitOptions) @(TestAssembly)</NUNitCommand>
</PropertyGroup>
<Exec Command="$(NUnitCommand)">
<Output TaskParameter="ExitCode" ItemName="ExitCodes" />
</Exec>
</Target>
<Target Name="Package" DependsOnTargets="Test">
<MSBuild Projects="$(MyApp)\$(MyApp).csproj"
Properties="Configuration=$(Configuration);DeployOnBuild=True;PublishProfile=$(PublishProfile)" />
<ItemGroup>
<OutputFiles Include="$(MyApp)\obj\Package\**\*.*"/>
</ItemGroup>
<Copy
SourceFiles="@(OutputFiles)"
DestinationFiles="@(OutputFiles->'.out\Package\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
</Project>
internal sealed class Configuration : DbMigrationsConfiguration<MyAppContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(MyAppContext context)
{
...
}
}
// In Application_Start()
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyAppContext, Configuration>());
public class MyAppContext : DbContext
{
public DbSet<Thing> Things { get; set; }
public MyAppContext() : base("MyAppContext") { }
...
}
public class Thing
{
public long ThingId { get; set; }
public string Name { get; set; }
}
<connectionStrings>
...
<add name="MyAppContext" providerName="System.Data.SqlClient" connectionString="Server=.\SQLEXPRESS;Database=MyApp;Integrated Security=True;" />
</connectionStrings>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="Environment" value="Test" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment