torsdag 26 november 2009

app.config transformation with the new MsBuild task XslTransformation in .NET4

I want to have different connection strings, server paths, etc. in my app.config files for different build configurations. MS have solved this in a nice way inVS2010 Web Deployment with web.config transformations but that's regretfully not available in my non web projects.

I'm trying to accomplish something similar to my app.config files by including xslt files in my projects and then have MsBuild execute transformations at build time. I just found that in version 4 of the Microsoft.Build.Tasks (Microsoft.Build.Tasks.v4.0.dll) there is a new task called XslTransformation which is cool, as we no longer have to write our own custom task for this!

By using a simple xsl file with the following contents I can replace a named connection string (Test) with a new one. This is very similar to the behaviour of the web.config transformations though the XDT syntax is a bit simpler.

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>

<!-- Default template -->
<xsl:template match="@* node()">
<xsl:copy>
<xsl:apply-templates select="@* node()"/>
</xsl:copy>
</xsl:template>

<!-- Connection string replacement template -->
<xsl:template match="/configuration/connectionStrings/add[@name='Test']">
<add name="Test" connectionString="NewValue" providerName="System.Data.EntityClient" />
</xsl:template>
</xsl:stylesheet>

onsdag 25 november 2009

UNIQUE constraint on properties in the EDM (EF4)

There is no built in way of accomplishing this. The best way I've found to do this is to:
  1. Modify the database generation workflow, look for annotations in the CSDL and move them to the SSDL. This post by Dan Simmons on the EF-team explains how to do it.
    Modify the T4 that sits behind the SSDL to DDL activity and have it produce a UNIQUE constraint for each field that has been annotaded.
  2. Build an extension to the EF designer / property sheet to allow for annotations to the Entity Properties. An example on how to do this can be found in ADO.NET Entity Data Model Designer Extension Starter Kit.
  3. Annotate the Entities/Properties in you EF Data Model where you want to have a UNIQUE constraint.

Started to blog (again).

I've realized I need to start blogging (again). The project I'm working on is all VS2010/.NET4, EF Feature CTP and soon also WCF/WF hosted in AppFabric.

In this blog I'll try to write a bit about problems and ideas we come across during the project and how we solve and implement them.

Stuff that I haven't written about (but might on request) include:
  • Modifications to the EF Feature CTP 1 - Self Tracking Entities types.tt T4.
    Including implementation of
    INotifyPropertyChange
  • How to workaround database-generation bug in EF4 when having set ConcurrencyMode for a property.
  • How to allow for rowversion type in generated DDL from EF Data Model
  • How to overcome incompability between EF Feature CTP1 and EF4 Beta 2 by creating a 'FrankenBuild' of the CTP1.
Hope you will enjoy this blog (and that I can deliver)