Last Updated: December 26, 2018
·
2.481K
· adamhewitt627

Multiple output types from Visual Studio

I've recently come across a need to use reflection on a Windows Runtime component that is written in C#. The challenges:
1. Since it is being consumed by a JavaScript/HTML Windows 8 app, it must be a WinRT component, thus no DLL.
2. The resulting .winmd file is not compatible with the C# reflection API, specifically the "Load" methods.
3. I am using the reflection API from a standard C# console application, which can thus not reference the output as a reference and do something like: typeof(MyClass).Assembly

What I really need is a DLL that compiles against the Windows Store API, and automatically matches the configuration of my main development library.

The solution: a second .csproj file in the same directory (so all relative paths match) with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <ProjectGuid>{12345678-6543-7890-2345-5678901234567}</ProjectGuid>
  </PropertyGroup>
  <Import Project="WinRTComponent.csproj" />
</Project>

Within WinRTComponent.csproj find the OutputType line and add a condition like:
<OutputType Condition=" '$(OutputType)' == '' ">winmdobj</OutputType>

I would expect a similar method to be useful for other combinations of output types as well.