1

I have a library called foo, which is written in C++/CX. I chose a Windows Runtime Component because I want it to be projected into C#, C++ and JavaScript. Also, I want to be able to distribute the library, and I don't want to require/allow the consumer to load my project, along with the source files, in the same solution as their project.

The instructions on MSDN only demonstrate how to include the Windows Runtime Component project in a solution with the consuming C# project. I know there is a way to only distribute the binary, but I don't know how.

This question has been asked a thousand times, but the answer always has the two projects in the same solution, is incomplete or a workaround.

I'm using Visual Studio 2013.4 on Windows 8.1.

Zak
  • 12,213
  • 21
  • 59
  • 105
  • There is no such way. The components needed for a Store app must always be included in the package that the user downloads from the Store. For a good reason, somebody with a phone or a slate doesn't stand a chance to troubleshoot a DLL Hell problem. – Hans Passant Feb 24 '15 at 16:03
  • OP didn't talk about not including the component itself (i.e. the DLL). He said that he wants to provide the component as a library to be consumed by others, without having to distribute the sources and the project file (which is a legitimate request). – Guy Apr 26 '15 at 18:05

2 Answers2

3

One way to do it is to create a VSIX package of your component. See Walkthrough: Creating an SDK using C++ that shows exactly how to do this with a WinRT component consumed by a C# project.

Peter Torr - MSFT
  • 11,824
  • 3
  • 18
  • 51
  • On a quick look, it demonstrates how to consume a WinRT component in a test application of the same flavor (i.e. `C++` -> `C++`, `C#` -> `C#`, etc...). There are actually subtle nuances that must be respected when consuming `C++` in a `C#` project, which I attempted to address in my answer. – Zak Feb 26 '15 at 04:35
  • I'm wondering - did you try creating a VSIX (which isn't very easy...) and consume it? because from my experience, when you create a C++/CX component with the right flags (/ZW), you shouldn't have issues adding it to a C# win app. – Guy Apr 26 '15 at 18:07
0

I researched and found the answer... It is not documented well, it is not intuitive, but it's worth the trouble when you see how well a Windows Runtime Component works.

Compiling the C++/CX library:

Make sure you compile the library for all permutations of Debug and Release, in Win32, ARM, x86 and x64.

Instructions for consuming in C#:

Right-click on References in the Solution Explorer, and add a reference to the Microsoft Visual C++ Runtime Package v12.0. Then add a reference to the binary you created with the appropriate configuration for your project (i.e. Debug/ARM). This step is tricky, because the file filter prompts you for the .dll, but you need to set the filter to *.* and select the .winmd file. Then you unload the project, find the <Reference> tag for the library you just added. <Reference> will have a <HintPath> tag below it, and under <Reference> you will also need to add <IsWinMDFile>true</IsWinMDFile> and an <Implementation> tag pair loaded with the name of the .dll that was sitting in the same folder as the .winmd file.

For more detailed instructions and information, I highly recommend visiting Mike Taulty's Blog

Zak
  • 12,213
  • 21
  • 59
  • 105
  • 1
    I wouldn't vote this down, because this method would work. But can you imagine providing a library to a client, to be used in a VS project, and instructing him to add the reference to your library (after forcibly choose a WINMD when the only option suggested by the UI is a DLL), unload the project, open the project file as text, and manually add the "Implementation" tag? I would have to be very desperate to consume such external library... – Guy Apr 26 '15 at 18:10