1

My VS 2010 solution has let's say 1 native C++ dll project and 1 c# wrapper project. What I want is a pure magic. My solution has 32 and 64 bit configurations, mostly because of native dll. I'd like to build the solution so that c# dll includes both 32bit and 64bit native dll as resources in c# dll. Then I will unpack proper bitness in runtime and use it (this is not a problem). My question is how do I configure VS solution to build both bitnesses and then put them into the C# project before it builds?

I could probably do a clever .msbuild script, but then I won't be able to build nicely from VS.

1 Answer 1

1

You can do the following:

  1. Right-click on the C# project in Solution Explorer and select Unload Project.
  2. The project will be unloaded. Right-click on the project again and select Edit *.csproj.
  3. Now you can edit the project file inside Visual Studio. *.csproj file has rather simple XML format.
  4. Go down the *.csproj file right before </Project> closing tag.
  5. Add the following lines:
    <Target Name="BeforeBuild">
        <MSBuild Projects=".\..\NativeLibrary.sln" Properties="Configuration=Release;Platform=x64"/>
        <MSBuild Projects=".\..\NativeLibrary.sln" Properties="Configuration=Release;Platform=Win32"/>
    </Target>

No, you can right-click on the project file in Solution Explorer and select Reload Project.

Also, you will need to add 32-bit and 64-bit *.dll files to resources. I have used this approach for a long time and it works perfectly. You can build your C# project from inside Visual Studio.

3
  • Actually i'm doing now the build of that native project instead of the whole solution in <beforebuild> as the solution is huge. Then pre-build step to copy natives into Resources subfolder. It works!
    – Ivan G.
    Nov 10, 2011 at 9:03
  • Thanks again, everything nicely integrated with build server, I now have the magic assembly I dreamed about :)
    – Ivan G.
    Nov 10, 2011 at 12:34
  • You are welcome. Actually I am using even more complicated approach as you do. I also compress native 32-bit and 64-bit libraries using LZMA algorithm (from 7-Zip) before including into resources.
    – vharavy
    Nov 10, 2011 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.