Relative Path to DLL References in LightSwitch Projects

When I was writing unit tests for an ODataController I needed the references to the Microsoft.Lightswitch.dll and to the Microsoft.LightSwitch.Server.dll in the unit test project. I tried to add them with the Reference Manager in Microsoft Visual Studio (Solution Explorer: Right click on references -> Add reference…) but couldn’t find the references. The Reference Manager allows you to browse for a dll so I checked the paths of the references I searched for in the main project and added them by browsing. When doing it this way the path to the references will be absolute and it’s better having relative paths in a project. I had a look into the csproj-file of the main project to check out how this problem is solved in the main project and I found the following lines of configuration:

    <MicrosoftSdkDir Condition=" '$(MicrosoftSdkDir)' == '' ">$([System.IO.Path]::Combine($(MSBuildProgramFiles32), 'Microsoft SDKs'))</MicrosoftSdkDir>
    <LightSwitchSDKPath Condition=" '$(LightSwitchSDKPath)' == '' ">$([System.IO.Path]::Combine($(MicrosoftSdkDir), 'LightSwitch', $(LightSwitchVersion)))</LightSwitchSDKPath>
    <LightSwitchSDKPath Condition=" '$(LightSwitchSDKPath)' != '' and !HasTrailingSlash('$(LightSwitchSDKPath)')">$(LightSwitchSDKPath)</LightSwitchSDKPath>

The properties are defined in the first PropertyGroup tag

   <Reference Include="Microsoft.LightSwitch">
    <Reference Include="Microsoft.LightSwitch.Server">

The references are defined in the first ItemGroup tag

To solve the problem of having absolute paths in the test project I took the above configuration snippets and manually added them to the corresponding sections in the csproj file of the unit test project.

IMPORTANT: If the references were already added with the Reference Manager (with absolute paths) they have to be deleted from the csproj file after adding the references with relativ paths.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: