Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have the following question:

I have a VS10 project which has several files. Actually, not all files already exist. (i have included references to them)

The files which do not already exist, will be created by a tool, say foo.exe, in a custom-build step, which will be executed before compilation. This tool takes one file (all of a certain extension, say .def, which is only there, to create the new file, it will never be compiled) and creates a new file. So far so good.

Problem: I have multiple projects, for which i have to accomplish this task and i don't want to write for each file i have to create, that foo.exe takes a certain foo2.def to create a certain file.

Is there a way to say Visual Studio, that every file with a certain extension (here: .def) has to be taken by the tool to create another file?

Perhaps by a .props-file or something like this? Which i can include in all project-files (.vcxproj).

thx alot for any help!
Posted
Updated 6-Jan-15 9:30am
v2

Use build-events[^]. Remember that the events are essentially any command line call, so you can easily call a script that does whatever you need. Your script can be anything that can be called from the command line (you can use python/perl or something else that's already natively supported in Windows).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Jan-15 17:21pm    
5ed (nice short manual is referenced, it looks like), but there is a much more robust approach. Please see Solution 2. I tried to explain its benefits.
—SA
Albert Holguin 7-Jan-15 14:58pm    
Just used the reference because it was the first thing I found with the picture of the build-events section in Visual Studio. I didn't exactly remember what it was called so I had to do a quick search. I mostly work in Linux nowadays.
The better way to customize build and create your own steps would be using the MSBuild project file standard directly. Please see:
http://msdn.microsoft.com/en-us/library/wea2sca5%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/7z253716.aspx[^].

You can create your own code for a custom step, which cannot be something better than the application or a batch script to be launched as a separate process. The better approach is to develop the custom Task assembly using MSBuild API. This assembly gets all required information from the build process and the project (options, file names, parameters) and can manipulate them and is expected to produce output integrated into the build process. This is a very well-designed, well-integrated and robust approach, with all elements highly standardized. At the same time, you can easily integrate 3rd-party build code, and even 3rd-party build applications without source code (which I would not prefer). It correctly works with time stamps, incremental build and rebuild, cleaning, all that. Please start here:
http://msdn.microsoft.com/en-us/library/ms171466%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/7z253716.aspx[^].

Note that you can easily organize the build to have your custom Task assemblies compiled before other steps and then used in the build, so you don't need to have any executable, only pure source code. This is much better for good maintenance.

In a pinch, for solving simpler problems you can use the approach explained in Solution 1. But the custom steps based on such approach look and behave like "foreign" elements and are not as good for maintainability.

—SA
 
Share this answer
 
v2
Comments
Member 10781325 7-Jan-15 7:26am    
Ok, i have broken down the problem now to the following problem:

how can i set the order in which the external tool converts the included files?

any ideas?
Sergey Alexandrovich Kryukov 7-Jan-15 10:45am    
MSBuild project language is a declarative language. The order is defined by the dependencies and timestamps. You define which Target depends on which Targets. If some target1 needs rebuild (which is seen by its timestamp) and some target2 needs to be built and it depends on target1, target1 will be built first. The dependency can be calculated by MSBuild implicitly or it needs to be specified explicitly. To specify it explicitly (which is typical for custom steps), use the attribute DependsOnTarget:
http://msdn.microsoft.com/en-us/library/t50z2hka.aspx.
—SA
Albert Holguin 7-Jan-15 15:02pm    
Seems like a great solution... +5
Sergey Alexandrovich Kryukov 7-Jan-15 15:46pm    
Thank you, Albert.
By the way, I used to develop custom MSBuild project which played the role of the master project, with target items being solutions, not projects (each solution having their separate subset of the projects). The motivation was having some layered structure, with separate solutions per layers, automated full build on top, with custom Tasks built in order; it allowed to have cleaner separate solutions, which allowed to work in a single layer during development, since having fully integrated single code base and build. Such effort makes really sense for bigger code base covering a set of products deployed separately or based on custom feature set per each deployment.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900