conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.96k stars 952 forks source link

[build system][MSBuild] Investigate Microsoft.Cpp.Default.props #3859

Open memsharded opened 5 years ago

memsharded commented 5 years ago

https://msdn.microsoft.com/en-us/library/669zx6zc.aspx

This file is automatically loaded by the IDE, so might be a good mechanism to define conan dependencies properties.

solvingj commented 5 years ago

The other option is Directory.Build.props and/or Directory.Build.targets.

https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2017

memsharded commented 5 years ago

I was investigating this, and the value seems marginal: It only works in VS >15. The default can't be changed without breaking, so generating conanbuildinfo.props is still a must. Writing also a Directory.Build.props could overwrite existing users file, not easy to differentiate if it is a file from user or a file from Conan (yes we could check some patterns, but still seems a bit fragile).

We will have a look again when revisiting the build helpers and generators.

SSE4 commented 5 years ago

about MSBuild targets vs Add-on (plug-in): the main disadvantage of MSBuild targets is inability to subscribe on solution load event. as result, it has the following consequences (as GUI and IntelliSense load before any MSBuild tasks run):

santhonisz commented 1 year ago

Hi there,

As part of our preparation for the upcoming release, I have been looking at the latest Conan 2.0 MSBuild generators and came to the same thought as was raised many years ago in this issue. Namely, I was wondering of the value in the creation/modification of a Directory.Build.props file as part of the new MSBuildToolchain generator. This would provide a very convenient approach to automatically including the new conantoolchain.props file without having to manually add it the relevant .vcxproj file. In our company's case we have literally hundreds of individual projects and Conan recipes, so anything that can steamline the process of updating to the new generators would be beneficial.

I have done some experimentation and by using the ForceImportAfterCppDefaultProps property the conantoolchain.props can be imported as desired, ensuring the platform toolset is applied e.g.

<?xml version="1.0" ?>
<Project>
    <PropertyGroup>
        <ForceImportAfterCppDefaultProps>..\conan\conantoolchain.props</ForceImportAfterCppDefaultProps>
    </PropertyGroup>
</Project>

I would think the same logic could also be applied to the MSBuildDeps generator in order to auto-import the conandeps.props file (I'd suggest using the ForceImportAfterCppProps property in that case).

Is there any appetite for this change; I feel it could go a long way to simplifying the process for integrating Conan with MSBuild projects? I am happy to submit a PR with the work I have done, but obviously don't want to go the effort of writing tests etc. if there's no desire for the functionality 😄