Category Archives: technology

Shared Transformable App/Web Config

Nice way to keep your config in one place for all types of projects is using web config transformations in addition to using shared (using Link) config files with DependentUpon back to the root config file, e.g. App.Config

Using the standard web config transforms, e.g:

In App.config

 <connectionStrings>
    <add name="Db" connectionString="Server=localhost;Port=3306;Database=myapp;
Uid=myappuser;Pwd=secret;/>
  </connectionStrings>

In App.Production.config

 <add name="Db" connectionString="Server=production;Port=3306;Database=myappprod;
UId=produser;Pwd=supersecret;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>

This will transform your out so you have a production config file which overrides the standard config file. as documented here:
Web Config Transforms

But what if you need the config shared across projects, e.g. Unit Testing, Integration testing, Tasks project etc…

Well you can use the standard Linked file approach, where you Add an existing item but select the little drop down on the add button.
The project file items will look like below.


<ItemGroup>
	<Content Include="..\Shared\App.config">
	<Link>App.config</Link>
	<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

<Content Include="..\Shared\App.Local.config">
	<Link>App.Local.config</Link>
	<DependentUpon>App.config</DependentUpon>
</Content>

<Content Include="..\Shared\App.Staging.config">
	<Link>App.Staging.config</Link>
	<DependentUpon>App.config</DependentUpon>
</Content>

<Content Include="..\Shared\App.Production.config">
	<Link>App.Production.config</Link>
	<DependentUpon>App.config</DependentUpon>
</Content>
</ItemGroup>

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />

<Target Name="PostTransformAppConfig" AfterTargets="TransformWebConfig">
	<Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" 
                  SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" DestinationFiles="$(OutputPath)\App.config" />
	<Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" 
                  SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" DestinationFiles="$(OutputPath)\App.config" />
</Target>

Then Just Call:

  msbuild myproject.proj /t:TransformWebConfig /p:Configuration=Production

And the output will be

 <add name="Db" connectionString="Server=production;Port=3306;Database=myappprod;
UId=produser;Pwd=supersecret;"/>

Will IronRuby take off???

Hi,

I’ve been working with ruby for about 6 months now on and off but the majority of my development is still in C#. So i’ve been keen to try out the possibility of using IronRuby with C#. I think the mixture of both langauges is compelling as there’s cases where a dynamic language is a better choice, more flexible and faster (development time).

Also with ruby there’s a really good opportunity to build internal DSL’s fast, and with an elegant end product. You only have to look at ActiveRecord in rails:

class Post < ActiveRecord::Base
  has_many :comments
  validates_presence_of :text

  ...
end

class Comment < ActiveRecord::Base
  belongs_to :post
  ...
end

and RSpec:

describe "(empty)" do
    it { @stack.should be_empty }
    it_should_behave_like "non-full Stack"
    it "should complain when sent #peek" do
      lambda { @stack.peek }.should raise_error(StackUnderflowError)
    end
    it "should complain when sent #pop" do
      lambda { @stack.pop }.should raise_error(StackUnderflowError)
    end
end

to be fair with the increasing number of fluent interface API’s in the .net world the drive towards more understandable code is not the preserve of the dynamic people.  With tools like StructureMap,

registry.AddInstanceOf<IWidget>()
 .WithName("DarkGreen")
 .UsingConcreteType<ColorWidget>()
 .WithProperty("Color").EqualTo("DarkGreen");

we get a very intuitive, understandable API which is also a DSL as far as i’m concerned. But i still believe that ruby’s looser syntax allows us to build nicer looking DSL’s :-)

I guess ultimately it’ll come down to how easy it is to use IronRuby with C#, how good the tooling is, for example RubyMine is a ruby IDE from Jetbrains (resharper) which provides refactoring support and with these guys on the case i feel confident that the ruby refactoring story will only get better.

I did a talk on Ruby/IronRuby for skillmatter a while back and speaking to everyone at the talk there was a consistent message, we like/love ruby, love the tools available, rspec, cucumber, rake etc but we really need stability & ide support.

Its arguable whether you need an ide, i used textmate for the majority of my rails dev, however i did find it alot easier once i started to use it in combination with rubymine. Textmate for cranking out the code (its gr8, no clunky huge ide in the way), but when things got messy (i.e. i couldnt figure out a problem) i was able to boot up rubymine and get the full visual studio like experience with debugging, break points, watches, hover over variables etc, all that good stuff.

So if we get this for IronRuby i.e. a texteditor (which there are already loads of, e.g. e-editior, notepad++ etc) and full visual studio support I think people would jump all over Ruby/IronRuby.

2 winners for typemock….

the guys behind typemock recently ran a little competition with bloggers as part of the launch…

i blogged about it here…  http://blog.mickdelaney.com/2009/05/20/typemock-launch-a-new-asp-net-bundle/

luckily i was a winner of 2 licences to give away, so fellow blogger and colleague ian chamberlain from sysfutures http://systemfutures.com/IansBlog.aspx wins 1.. i know he’s a typemock fan… and my mate dean ward…  http://www.bakedbean.org.uk/  gets the other!!!

enjoy guys… :-)

problem with query_analyzer plugin

i moved from a mysql to sqlite db for local development.
when i did a rake db:migrate i got this error:

rake aborted!
undefined method `select’ for class `ActiveRecord::ConnectionAdapters::MysqlAdapter’

turns out it was the plugin query_analyzer.
so i just removed it and moved on.. :-)

a nicer powershell prompt

taken from: http://flanders.co.nz/2009/03/19/pimp-your-command-line-for-git/

install powershell (i’m using v2 ctp)

run in powershell:

Set-ExecutionPolicy Unrestricted

create txt file:

%MYDOCUMENTS%\WindowsPowershell\profile.ps1

paste this into the file:
function prompt

{

$host.ui.rawui.WindowTitle = $(get-location)

Write-Host (“+ ” + $(get-location)) -foregroundcolor Yellow

$branches = “”

git branch | foreach {

if($_ -match “^*s(.*)”){

$branches += $matches[1]

}

}

if($branches){

Write-Host (“(” + $branches + “) “) -nonewline -fore Cyan

}

Write-Host (“»”) -nonewline -foregroundcolor Green

return ” “

}