Presentation is loading. Please wait.

Presentation is loading. Please wait.

IPABS 3 Configuration and Build Management Richard Rush.

Similar presentations

Presentation on theme: "IPABS 3 Configuration and Build Management Richard Rush."— Presentation transcript:

1 IPABS 3 Configuration and Build Management Richard Rush

2 1 IPABS 3 Configuration and Build Management Web.config Management Installer extension Build automation Version Numbering Future work

3 2 Web.config Management Implemented specifically to avoid the woes of multiple web.configs Use VisualStudios built-in Build Configuration features, as well as pre-compile commands

4 3 Web.config Management Each target environment gets its own named Build Configuration. For IPABS, these are: Debug Test UAT Staging Release Each Build Configuration gets a Web.config file, named Web.config.[Build Configuration]

5 4 Web.config Management Were using source control, however, which means Web.config might not always be editable, so first: attrib -R "$(ProjectDir)Web.config" Then, we use a pre-compile command to copy the appropriate Web.config.[Build Configuration] over Web.config "$(ProjectDir)utils\CopyIfDifferent.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config

6 5 CopyIfDifferent.bat @echo off echo Comparing two files: %1 with %2 if not exist %1 goto File1NotFound if not exist %2 goto File2NotFound fc %1 %2 if %ERRORLEVEL%==0 GOTO NoCopy echo Files are not the same. Copying %1 over %2 copy %1 %2 /y & goto END :NoCopy echo Files are the same. Did nothing goto END :File1NotFound echo %1 not found. goto END :File2NotFound copy %1 %2 /y goto END :END echo Done.

7 6 Pre-build events

8 7 Installer Extension Automate tedious, repetitive tasks Produce a more professional looking product Enable non-developers to deploy the application

9 8 Example: Web.config Encryption Encrypt sections of Web.config AppSettings ConnectionStrings Previously done with a batch file aspnet_regiis -pe "appSettings" -app "/IPABS3" aspnet_regiis -pe "connectionStrings" -app "/IPABS3" Now done as part of the installation process

10 9 Extending the Installer 1.Add the custom actions to the installer project 2.Add new dialogs to the installer user interface 3.Provide parameters you need to the custom actions 4.Define the custom Installer class 5.Override the action methods

11 10 View Custom Actions

12 11 User Interface Add Dialog

13 12 View User Interface

14 13 Encrypt Web.Config Dialog

15 14 Custom Action Parameters Follow the format /ParameterName=ParameterValue

16 15 Custom Action Parameters The parameters to the custom Commit action are: /targetvdir="[TARGETVDIR]" /EncryptAppSettingsCheckbox="[ENCRYPTAPPSETTINGSCHECKBOX]" /EncryptConnectionStringsCheckbox="[ENCRYPTCONNECTIONSTRINGSCHECKBOX]" These values are being pulled from the Installer configuration and Installer UI controls.

17 16 Custom Installer Actions Define an Installer class Inherit from System.Configuration.Install [RunInstaller(true)] Implement the custom action behavior public override void Commit(IDictionary savedState) { } Call the base implementation base.Commit(savedState); Access Installer data EncryptWebConfig(Context.Parameters["TargetVDir"]);

18 17 Example: Custom Installer Actions using System.Configuration.Install; namespace PPC.Ipabs { /// /// Custom IPABS Web Application Installer /// [RunInstaller(true)] public partial class IpabsInstaller : Installer { /// /// Handles the Commit action for IPABS 3 /// /// State Dictionary public override void Commit(IDictionary savedState) { base.Commit(savedState); try { EncryptWebConfig(Context.Parameters["TargetVDir"]); } catch (Exception ex) { // Handle the exception! }

19 18 Example: Encrypting Web.config /// /// Encrypts the Web.config /// /// Application to encrypt the Web.config for private void EncryptWebConfig(string applicationName) { bool encryptConnectionStrings; Configuration configuration; // Get the installer encryptConnectionStrings = Convert.ToBoolean((int)Context.Parameters["EncryptConnectionStringsCheckbox"]); configuration = WebConfigurationManager.OpenWebConfiguration("/"+ applicationName); // Protect the ConnectionStrings section if (encryptConnectionStrings && !configuration.ConnectionStrings.SectionInformation.IsProtected) { configuration.ConnectionStrings.SectionInformation.ProtectSection(String.Empty); } // Save the configuration try { configuration.Save(); } catch (Exception ex) { //TODO: Handle the exception! } }

20 19 Build Automation Done to avoid tedious, repetitive tasks Produce a build for each configuration simultaneously Currently done with a batch file

21 20 BuildAllConfigurations.bat Called with the format: BuildAllConfigurations InstallProjectName BuildConfigurationName[,BuildConfigurationName+] So: BuildAllConfigurations IPABS Debug,Test,UAT,Release

22 21 BuildAllConfigurations.bat Pseudocode 1.Load the VisualStudio 2005 environment variables 2.Determine the timestamp 3.Clean the solution 4.Build each specified configuration :PERFORM_BUILD IF (%1)==() GOTO DONE_BUILDING ECHO Building %1... RMDIR /S /Q %1 DEVENV %ProjectName%.vdproj /build %1 COPY /Y "%1\%ProjectName%.msi" "Builds\%date% %ProjectName%\%1 %date% %ProjectName%.msi" ECHO Done building %1... SHIFT GOTO PERFORM_BUILD :DONE_BUILDING

23 22 BuildAllConfigurations.bat Results

24 23 Version Numbering Version numbers are attributes of an assembly Can be accessed at runtime through reflection Can be significant when referencing external libraries Useful for tracking features (versioning? crazy talk!)

25 24 Version Numbering Microsofts Recommended format: [Major Version].[Minor Version].[Build Number (yyMMdd)].[Revision] Software Solutions Developments common library format: [Major Version].[Minor Version].[Build Number (yyMM)].[Revision] Why the difference? Revision is handled as a short (int16) internally (int) 070101 > 65,535 With the yyMMdd format, anything from 2007 onward is too large

26 25 Version Numbering Are set in AssemblyInfo.cs (or AssemblyInfo.vb) Two attributes: AssemblyVersion Can be automatically incremented Displayed in the Properties Screen of the.dll AssemblyFileVersion Cannot be automatically incremented Displayed in Windows Explorer

27 26 Version Numbering We want to use AssemblyFileVersion We want it automated Custom MSBuild task: AssemblyInfoTask Developed by the MSBuild team Source available from GotDotNet Modified installer assembly with SSDs version number format VisualStudio build process does not provide the Build Configuration to its implementation of MSBuild This will… complicate things

28 27 Using PPC AssemblyInfoTask 1.Run PPC AssemblyInfoTask.msi Select Install to Users Application Data folder 2.Update the project definition file (.csproj or.vbproj ) Add a call to the AssemblyInfoTask build task 3.Check out AssemblyInfo.cs (or AssemblyInfo.vb ) AssemblyInfoTask will be updating this file 4.Build the library using MSBuild, not VisualStudio Set up the MSBuild external tool Build using this when building to Release

29 28 PPC AssemblyInfoTask Installer

30 29 Update.csproj or.vbproj <!-- Or, as appropriate: --> <Import Project="$(APPDATA)\Microsoft\MSBuild\AssemblyInfoTask\Microsoft.VersionNumber.Targets" Condition=" '$(Configuration)' == 'Release' " />

31 30 External Tools Dialog Command: Path to MSBuild.exe Arguments: $(ProjectDir)$(ProjectFileName) /m /p:Configuration=Release Initial Directory $(ProjectDir) Use Output window Prompt for arguments

32 31 Future Work Automate source control access Visual SourceSafe Team Foundation Is this as bad an idea as I think it is? MSBuild automation? Why use DEVENV in the build script when we could use MSBuild? Custom MSBuild tasks wont work with DEVENV.Net Console Application? Why use a.bat file when we could use managed code? Third Party Tools Who likes reinventing the wheel?

Download ppt "IPABS 3 Configuration and Build Management Richard Rush."

Similar presentations

Ads by Google