Is there a way to auto generate "Additional Dependencies" for "Custom Build" in Visual Studio?
Asked Answered
W

1

9

I have a custom build step in a Visual Studio 2013 solution. The custom build step calls a python script on a text file that refers to several other files in my solution. I want the custom build step to be called whenever any of those files change or when the output of my script is missing. However, I don't want to manually maintain the custom tool "additional dependencies" and "outputs" fields.

I can easily make the script generate a list of dependencies in the same way that gcc can generate a .d file when passed in -MM. Is there a way I can use the .d output of my script to automatically populate the "Additional Dependencies" in my Custom Build step? Is there some other way to avoid maintaining the "additional dependencies" and "outputs" fields"?

The help page only shows how to add individual files.

Wagon answered 18/3, 2013 at 23:53 Comment(0)
T
10

Assuming that your script for generating .d files can generate files in any format that you want, you should be able to achieve the results that you need with the use of Import element:

  1. Write a script that produces a small project file instead of a .d file. The output of your script would be a small project file that contains the "additional dependencies" and the "outputs" fields.
  2. Use the Import tag to make the generated file a dependency of your main project
  3. Run the script as needed when the composition of your dependencies changes.

This approach lets you maintain the main project file separately from the auto-generated dependency file, which could be re-generated as needed. The only drawback is that your generated dependency file is an MSBuild project file, not a pure dependency file. However, this should not be a huge problem, because you own the script that generates the dependency file.

Taverner answered 10/6, 2014 at 16:43 Comment(4)
do you really think that a scrip that creates a secondary project file, for later "importing" it from the main project, is a simpler approach than just programmatically adding the required dependencies to the main project xml file??Figuration
@Figuration Why, I don't think, I know for a fact that this approach is a lot cleaner, and a lot more stable in the long run.Taverner
with all due respect your answer is not good; you invite to programmatically create a new project for importing the project, for importing the dependencies with it; my answer directly adds the dependencies to the main project file; I think your answer does not compete with mine; you just took part of mine and made it way more convoluted and complicated.Figuration
@Figuration I've cleaned up the comments because they were getting out of hand. If you have an issue please take it to chat or bring it up on Meta. Please don't continue to argue about this here, it is not constructive and you've made your point in the comments that remain.Myrlmyrle

© 2022 - 2024 — McMap. All rights reserved.