简体   繁体   中英

How do you install a Windows Runtime Component built in C++/CX into a C# project?

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.

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.

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 (ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM