conan-io / conan-vs-extension

Conan Extension for Visual Studio
https://marketplace.visualstudio.com/items?itemName=conan-io.conan-vs-extension
MIT License
58 stars 34 forks source link

Add Exists guard for import of conanbuildinfo.props #176

Closed lieser closed 6 months ago

lieser commented 4 years ago

If the generated conanbuildinfo.props no longer exists, the projects fails to load because the added import fails. As it seems to not be possible trigger the execute for a project that is not loaded, it means one has to revert the change done by the extension to the project file.

Would be nice if the Exists condition (https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditions?view=vs-2019) would be used to guard the import. E.g.

  <ImportGroup Label="PropertySheets" Condition="Exists('conanbuildinfo.props')">
    <Import Project="conanbuildinfo.props" />
  </ImportGroup>
talyz commented 4 years ago

Yes, it currently seems like one has to add the conanbuildinfo.props file to source control, but since it's rewritten on build config change, it constantly changes, which isn't ideal. Is there any other way around this?

lieser commented 4 years ago

You could try manually adding the exist guard to the line added by the extension yourself. e.g..:

-<Import Project="conanbuildinfo.props" />
+<Import Condition="Exists('conanbuildinfo.props')" Project="conanbuildinfo.props" />

At least in the small experiment I did, the extension still regarded the entry with the added guard as it's own, and did not create a new one without the guard.

talyz commented 4 years ago

I did, but wasn't so lucky - the extension created a second entry and broke the project :/

talyz commented 4 years ago

For now, my solution is to run conan install in our conan setup batch script:

if not exist "path\to\build\output\.conan\conanbuildinfo.props" (
    @echo Creating initial conanbuildinfo.props file...
    conan install "path\to\conanfile.txt" ^
                  -g visual_studio ^
                  --install-folder "path\to\build\output\.conan" ^
                  --profile "path\to\source\winproj\conan_x86_64_release.profile" ^
                  --build=outdated ^
                  --update  >tmp_out 2>&1 || (type tmp_out & pause & del tmp_out & exit /b 1) & del tmp_out
)
Woazim commented 3 years ago

It seems to be the same problem as in issue #128. I propose a workaround in extension for this case. See #185.

vapdrs commented 3 years ago

I was able to get the extension to recognize the entry. I would suggest verifying that the Extension's configured destination for the props file is the same as the Import Line. I would also suggest converting the hardcoded path that the extension generates to one with variables. For example the default destination would be,

<Import Condition="Exists('$(OutDir)\.conan\conanbuildinfo.props')" Project="$(OutDir)\.conan\conanbuildinfo.props" />
vapdrs commented 3 years ago

An additional note is that I found this only work with Relative paths. Also it never works when the build directory is non-existent. Like on a fresh clone. Once the directory does exist though, this extension doesn't re-add