To start using the Smith Build extensions is really easy, simply download the code, build it and copy the Smith.BuildExtensions.dll to a directory of your choosing.

Then either create or copy the provided examples of config files and put those in another directory of your choosing.

Then you need to change all project files that you want transformations for.

Add the following line to the project that you want to have configuration transformations in:

<UsingTask TaskName="ConfigTransformTask" AssemblyFile="Smith.BuildExtensions.dll" />

But remember to change the AssemblyFile attribute to point to where you put the compiled Smith.BuildExtensions.dll file.


Uncomment the
<Target Name="BeforeBuild">

target and add the following to the target:

<Target Name="BeforeBuild">
   <ConfigTransformTask ConfigBaseDir="..\Configs" ConfigTemplate="App.config.base.config" Configuration="$(Configuration)" Outputfile=".\App.config" />
</Target>

Where the ConfigBaseDir is where you have placed the app.config and web.config templates and the build specific settings files.

ConfigTemplate is the name of the template to use for transformation, i.e. if you are doing this in a web project choose your web.config.base.config file, and the app.config.base.config file if its a normal project or test project.

The OutputFile attribute controls what filename to write the file to, i.e. again for a web project use Web.config and App.config for other projects.

To see a full project file example, head over to the Project file example page

To see how to create the xml configuration files, head over to the Xml examples page.

If you have done everything on this page and get the following error when you build:
{System.UnauthorizedAccessException: Access to the path 'D:\kode\Smith.BuildExtensions\BuildExtensionsTests\App.config' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)
at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding)
at System.IO.File.WriteAllText(String path, String contents)
at Smith.BuildExtensions.BuildTasks.ConfigTransformTask.Execute() in D:\kode\Smith.BuildExtensions\Smith.BuildExtensions\BuildTasks\ConfigTransformTask.cs:line 51 D:\kode\Smith.BuildExtensions\BuildExtensionsTests\BuildExtensionsTests.csproj 83 3 BuildExtensionsTests
}

Then you need to check out your app.config from TFS, SVN etc., because its read only.

To prevent this error, you have to include the App.config in the project, but exclude it from source control.

Last edited Feb 3, 2012 at 7:44 PM by bjornbouetsmith, version 7

Comments

No comments yet.