I've come up with nice work-around for NCrunch / PCL projects to work nicely together and not have to have a (dummy) mirror project in your solution.
1. For your PCL project's configuration within NCrunch, specify a build configuration like ("ncrunch") in the "Use build configuration", component configuration. This should not be a legitimate build configuration, but one to recognize that the build is triggered by NCrunch.
2. Modify your PCL project .proj file.
Here is my example PCL which support multiple build configurations and one specific for NCrunch.
Code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="(- BROKEN LINK -)">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Framework Condition=" '$(Framework)' == '' ">portable-net4+sl4+wp7</Framework>
<ProjectGuid>{2EC085CE-BF81-46ED-A2D7-8CD0B9AFDEC2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NContext.Common</RootNamespace>
<AssemblyName>NContext.Common</AssemblyName>
<FileAlignment>512</FileAlignment>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
Now we have to reset the $(Configuration) to normal, Debug, and set an NCrunch specific property.
<!-- ================ NCrunch Pre Override ================== -->Code:
<PropertyGroup Condition=" '$(Configuration)' == 'ncrunch' ">
<Configuration>Debug</Configuration> <!-- Reset $(Configuration) -->
<NCrunch>true</NCrunch>
</PropertyGroup>
Configure the projects for each build target. (If needed)
Code:
<!-- ***********************************************************************************************************
* .NET 4.5 + Silverlight 4
*********************************************************************************************************** -->
<PropertyGroup Condition=" '$(Framework)' == 'portable-net45+sl4' ">
<!-- ============================================== DEBUG ================================================ -->
<DebugSymbols Condition=" '$(Configuration)' == 'Debug' ">true</DebugSymbols>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">full</DebugType>
<DefineConstants Condition=" '$(Configuration)' == 'Debug' ">TRACE;DEBUG;NET45;SILVERLIGHT40</DefineConstants>
<Optimize Condition=" '$(Configuration)' == 'Debug' ">false</Optimize>
<PlatformTarget Condition=" '$(Configuration)' == 'Debug DLL and Web' ">$(Platform)</PlatformTarget>
<!-- ============================================= RELEASE =============================================== -->
<DebugType Condition=" '$(Configuration)' == 'Release' ">pdbonly</DebugType>
<DefineConstants Condition=" '$(Configuration)' == 'Release' ">TRACE;NET45;SILVERLIGHT40</DefineConstants>
<Optimize Condition=" '$(Configuration)' == 'Release' ">true</Optimize>
<CodeAnalysisRuleSet Condition=" '$(Configuration)' == 'Release' ">AllRules.ruleset</CodeAnalysisRuleSet>
<!-- ========================================================================================================= -->
<DocumentationFile>bin\$(Configuration)\$(Framework)\NContext.Common.xml</DocumentationFile>
<OutputPath>bin\$(Configuration)\$(Framework)\</OutputPath>
<WarningLevel>4</WarningLevel>
<ErrorReport>prompt</ErrorReport>
<TargetFrameworkProfile>Profile23</TargetFrameworkProfile>
</PropertyGroup>
<!-- ***********************************************************************************************************
* .NET 4.0 + Silverlight 4 + Windows Phone 7
*********************************************************************************************************** -->
<PropertyGroup Condition=" '$(Framework)' == 'portable-net4+sl4+wp7' ">
<!-- ============================================== DEBUG ================================================ -->
<DebugSymbols Condition=" '$(Configuration)' == 'Debug' ">true</DebugSymbols>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">full</DebugType>
<DefineConstants Condition=" '$(Configuration)' == 'Debug' ">TRACE;DEBUG;NET40;SILVERLIGHT40;WINDOWS_PHONE7</DefineConstants>
<Optimize Condition=" '$(Configuration)' == 'Debug' ">false</Optimize>
<PlatformTarget Condition=" '$(Configuration)' == 'Debug DLL and Web' ">$(Platform)</PlatformTarget>
<!-- ============================================= RELEASE =============================================== -->
<DebugType Condition=" '$(Configuration)' == 'Release' ">pdbonly</DebugType>
<DefineConstants Condition=" '$(Configuration)' == 'Release' ">TRACE;NET40;SILVERLIGHT40;WINDOWS_PHONE7</DefineConstants>
<Optimize Condition=" '$(Configuration)' == 'Release' ">true</Optimize>
<CodeAnalysisRuleSet Condition=" '$(Configuration)' == 'Release' ">AllRules.ruleset</CodeAnalysisRuleSet>
<!-- ========================================================================================================= -->
<DocumentationFile>bin\$(Configuration)\$(Framework)\NContext.Common.xml</DocumentationFile>
<OutputPath>bin\$(Configuration)\$(Framework)\</OutputPath>
<WarningLevel>4</WarningLevel>
<ErrorReport>prompt</ErrorReport>
<TargetFrameworkProfile>Profile2</TargetFrameworkProfile> [color=red]<<<<<<<< NOTICE[/color]
</PropertyGroup>
<ItemGroup>
<Compile Include="Error.cs" />
<Compile Include="Extensions\HierarchicalDataExtensions.cs" />
<Compile Include="Extensions\IListExtensions.cs" />
<Compile Include="Extensions\IMaybeIEnumerableExtensions.cs" />
<Compile Include="Extensions\IResponseTransferObjectIEnumerableExtensions.cs" />
<Compile Include="IResponseTransferObject.cs" />
<Compile Include="Extensions\IResponseTransferObjectExtensions.cs" />
<Compile Include="IToken.cs" />
<Compile Include="Extensions\IMaybeExtensions.cs" />
<Compile Include="IMaybe.cs" />
<Compile Include="Just.cs" />
<Compile Include="Nothing.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceResponse.cs" />
<Compile Include="ValidationError.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(Framework)' == 'portable-net45+sl4' ">
<Compile Include="IStatefulResponseTransferObject.cs" />
<Compile Include="StateExtensions.cs" />
<Compile Include="StatefulServiceResponse.cs" />
</ItemGroup>
If this is an NCrunch build, let's modify a few property's that were just set to trick NCrunch into thinking this is a normal C# Library.
We do this by clearing ProjectTypeGuids and TargetFrameworkProfile
Then we add any references needed. (Make sure to do this in a Choose-When-Otherwise block or you'll run into an issue described here:
http://stackoverflow.com...-set-project-references
<!-- =============== NCrunch Post Override ================== -->Code:
<Choose>
<When Condition=" '$(NCrunch)' == '' ">
</When>
<Otherwise>
<PropertyGroup>
<ProjectTypeGuids></ProjectTypeGuids>
<TargetFrameworkProfile></TargetFrameworkProfile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
</Otherwise>
</Choose>
<Import Condition=" '$(NCrunch)' == 'true' " Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- ======================================================== -->
Code:
<Import Condition=" '$(NCrunch)' == '' " Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Target Name="AfterBuild" Condition=" '$(NCrunch)' == '' ">
<MSBuild Condition=" '$(Framework)' != 'portable-net45+sl4' " Projects="$(MSBuildProjectFile)" Properties="Framework=portable-net45+sl4" RunEachTargetSeparately="true" />
</Target>
</Project>
I'm currently using this for my project on GitHub, NContext. You can view it there. The PCL library is NContext.Common.
Hope this helps!I'll try and write up a blog post on this soon. Any questions, feel free to email me at
daniel@dgdev.net.