Closed jodylittle closed 5 months ago
Hi, @jodylittle. I have to say that this is not the workflow I have in mind when I'm thinking about the VS extension, so I will need more context.
IMHO the props
files are not to be committed with sources neither exported with the recipe. Conan should generate them at every machine, so all the users working on the project need to have the VS extension installed or need to run the conan install
command themselves with the proper parameters (to get the corresponding props
file at the expected path).
Maybe your use case is something we haven't think about yet: using Conan with a VS project works from the Conan client (as you said, the MSBuild
helper injects the property sheets), but if you want to build the project from VS you need to add the property sheets yourself. Is this the iissue?
Thanks
Hi @jgsogo, I'm not sure if the problem below is the exact same issue, but it seems quite similar.
Currently, it seems like we must either have the props
file checked into source control, or not check-in the changes to the .proj file. Neither of these seems ideal.
The VS extension generates the property sheet and adds it to the project. This property sheet is in $(OutDir).conan by default, so the vcxproj file will have a reference like:
<Import Project="..\x64\Debug\.conan\conanbuildinfo.props" />
Now if I want to create a package from my project, I call msbuild.build("my-project.vcxproj") from the recipe.
The property file is generated (at .\conanbuildinfo.props) and injected into the build command, but the build still fails because the vcxproj file is referencing "..\x64\Debug.conan\conanbuildinfo.props", which was not exported with the source.
@LBHawk, yes, two symptoms of the same problem. If the project will not load, you should be able to do an Install (Entire Solution) to generate the missing props files, then reopen the project.
This issue seems important to me, but I need to share it with the rest of the team to gather some feedback about the possible solutions. The ideal scenario would be to not commit the modified vcxproj
, so the ideal behavior would be if the extension doesn't modify the file at all... I need to investigate if we can achieve the same functionality without touching the project file in the filesystem.
things to investigate: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019
I've been reading and looking in the docs, trying to figure out how to address this issue and I haven't found an answer without changing current implementation. 😞
Using those special files in the link shared by @SSE4 would be nice, no need to modify the project file, but paths to includes won't be available for Intellisense or other tools
The best approach would be the Condition
in the Import
, but it looks like that programmatically there is no way to add/modify those conditions... the alternative is to edit the XML and reload the project which is very inconvenient for the user (although it has to be done only once, or when the path to the .props
file changes).
Using conan-vs-extension to perform an install modifies the .vcxproj file, adding references to the generated property sheets.
Subsequently, performing a conan create on the project will fail if the property sheets are not available. Because of this, I have to export *.props with the sources (or commit them, depending on the recipe).
The property sheets are unique to where they were generated, so this is not ideal. Is there an alternate solution?
I've explored a couple of potential changes to the extension, but without much success:
1) Add the property sheet to the project conditionally, like this:
<Import Condition="Exists('x64\Debug\.conan\conanbuildinfo.props')" Project="x64\Debug\.conan\conanbuildinfo.props" />
This works if I manually edit the vcxproj file, but the Visual Studio SDK does not appear to support this solution. VCConfiguration.AddPropertySheet does not support conditional clauses.
2) Override or add alternate Build and Rebuild events which call
VCConfiguration.BuildWithPropertySheetPath
, passing the property sheet.This would be equivalent to how Conan uses MSBuild with ForceImportBeforeCppTargets, but BuildWithPropertySheetPath appears to be deprecated in the VS 2019 SDK. Calling it was throwing an exception.
My current solution (pre conan-vs-extension) involves the visual_studio_multi generator and including the generated property sheet conditionally in an intermediary property sheet (which is exported and/or checked in). I.E. the project imports conansetup.props, which imports conanbuildinfo_multi.props if it exists.