Microsoft provides free Visual Studio Team Services for small team. It has free unlimited Git repositories and 4 hours per month to run builds, which should be more than enough for my projects.
I already integrated karpach.com front end and admin site. In this post I'll document how I integrated redboxnewreleases.com.
Step 1 Created build definition
My favorite browser is Google Chrome, but for below process I used Microsoft Edge, since some things didn't work in Google Chrome (e.g. reordering of build tasks).
I didn't use any templates and started with an empty process. First of all lets tried to build my solution. I used following tasks as is:
- Get sources (point to git repository)
- NuGet Restore **/*.sln (default settings)
- Build solution **/*.sln (default setting)
In my case the build failed with following error:
Error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\
Enterprise\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks" was not found.
In my previous CI system I used ExtensionPack for assembly version modification. This is old approach, so I just removed that task reference and used different approach to specify version later in the post.
I pushed a change, but it didn't trigger any build. I added a trigger then:
- Opened a Triggers tab.
- Enabled continuos integration trigger.
- Set repository setting to build on any master branch change.
- Went to options tab and set "Default agent queue": Hosted VS2017.
- Pressed Save & queue
This time build succeeded. Then I added assembly versioning back:
- Downloaded ApplyVersionToAssemblies.ps1 from https://github.com/tfsbuildextensions/CustomActivities.
- Deleted "$Env:TF_BUILD -and -not" from that powershell script.
- Replaced TF_BUILD with just BUILD in ApplyVersionToAssemblies.ps1.
- Added ApplyVersionToAssemblies.ps1 to Git repository.
- Went back to build definition web editor, switched to Variables tab. Added MajorVersion and MinorVersion variables there.
- Switched to the Options tab and filled "Build number format" field with $(BuildDefinitionName)_$(MajorVersion).$(MinorVersion).$(Year:yy)$(DayOfYear)$(Rev:.rr)).
- Made sure that AssemblyVersion and AssemblyFileVersion lines present in AssemblyInfo files (powershell script does replacement in those files).
- Added powershell task to run ApplyVersionToAssemblies.ps1.
- Moved up powershell task to run after Get sources task.
After that I modified msbuild task to produce a package for web deployment:
- Change build to build web csproj file instead of solution file
- Specified configuration: Release
- Used following MSBuild Arguments: /T:Package /P:PackageLocation=..\Artifacts\package.zip
- Added Publish Build Artifacts task:
Path to Publish = Artifacts\package.zip,
Artifact Name = Redbox
Step 2 Created release definition
- Started from Empty template.
- Picked my build from previous step.
- Added a deployment group phase task.
- Added "IIS Web App Deploy (Preview)" task.
- Created deployment group.
- Ran generated powershell script on my VPS hosting server.
- Specified website name: redboxnewrleases.com.
- Specified package folder using browse button to point to package.zip: $(System.DefaultWorkingDirectory)/Redbox-CI/Redbox/package.zip).
- Set trigger for continuous deployment.
- Optionally modified release name format in General tab: Release-$(Build.BuildNumber))