© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
1 reply
Tare

MSBuild For c# project with c++ dlls

So i have a c# project and a c++ cmake project ,
the c# project is referenced by the actual program so my structure is
Project A ( Some Cmake Project )
Project B ( Some Cmake Project )
Project C ( Some Cmake Project )
Project D ( Reference To Project A , B, C )

the cmake projects project build dlls to a folder and I start this build and copy the dlls using this msbuild target

<Target Name="BuildNative" BeforeTargets="BeforeBuild">
        <Exec Command="cmake -DCMAKE_BUILD_TYPE=$(Configuration) -S ./Native/ -B ./Native/build/$(Configuration)" />
        <Exec Command="cmake --build ./Native/build/$(Configuration)" />
        <ItemGroup>
            <NativeFiles Include=".\Native\bin\$(Configuration)\*.*" />
            <Content Include="@(NativeFiles)">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
                <Link>%(Filename)%(Extension)</Link>
            </Content>
        </ItemGroup>
    </Target>
<Target Name="BuildNative" BeforeTargets="BeforeBuild">
        <Exec Command="cmake -DCMAKE_BUILD_TYPE=$(Configuration) -S ./Native/ -B ./Native/build/$(Configuration)" />
        <Exec Command="cmake --build ./Native/build/$(Configuration)" />
        <ItemGroup>
            <NativeFiles Include=".\Native\bin\$(Configuration)\*.*" />
            <Content Include="@(NativeFiles)">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
                <Link>%(Filename)%(Extension)</Link>
            </Content>
        </ItemGroup>
    </Target>


This works for the first build or project D i.e. Clean => Build => Run
but when I do Clean => Build => Run => Change c# Code in project A or B or C references => Rerun
The dlls of the ones I did not change are not copied
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Build .sln with MsBuild
C#CC# / help
4y ago
Loading DLLs with same names
C#CC# / help
12mo ago
✅ Learning SQLite for C# Academy Project
C#CC# / help
3y ago