简体   繁体   中英

Ensure C++ project builds before .NET project with msbuild

I have an unmanaged C++ project, the output of which I need to copy to the output folder of a .NET project.

Visual Studio 2010 won't let me add the C++ project as a project reference as it isn't creating a managed assembly.

I've tried adding the following to the .csproj file manually but it doesn't seem to be working (eg. when running msbuild, the .NET project is being built first)

<ItemGroup>
    <ProjectReference Include="pathtoproject\unmanaged.vcxproj">
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
        <Private>False</Private>
    </ProjectReference>
</ItemGroup>

How can I enforce this build dependency to work with a command-line build?

So it turns out that the example I gave in the question is actually correct. That will cause the C++ project to build first.

My problem was that I was trying to hook in to the MSBuild targets in the .NET project to then copy down the C++ dll, and I was doing this too early in the build cycle for that project (I was hooking into BeforeBuild). Using the 'BeforeCompile' target instead seems to be late enough in the build cycle that it works properly.

Add both projects to a solution and use the project dependencies to make sure the the unmanaged project builds first. You can build a solution from the command line.

项目依赖对话框

I believe your question may have been answered in this thread:

How do I add a reference to an unmanaged C++ project called by a C# project?

Have a look at SLaks answer

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