Integrated Assemblies in Visual Studio

I have a few things that I cannot find in Visual Studio:

  • The pre-build step calls a code generator that generates some source files that are later compiled. This can be resolved to a limited extent by adding empty files to the project (which are later replaced by real generated files), but this does not work if I do not know the names and / or the number of automatically generated source files. I can easily solve it in GNU make with $(wildcard generated/*.c) . How can I do something like this with Visual Studio?

  • Can I prevent the pre-build / post-build event if the files do not need to be changed ( "make" behavior)? The current workaround is to write a shell script that will check the timestamps for me, which works, but is a bit awkward.

  • How can I find external libraries and headers installed outside of VS? In the case of * nix, they are usually installed on system paths or located in autoconf . I assume that I can specify paths with user-defined macros in the project settings, but where is a good place to place these macros so that they can be easily found and adjusted?

To be clear, I know that there are better Windows build systems ( CMake , SCons ), but they usually generate the VS project files themselves, and I need to integrate this project into the existing VS build system, so it’s advisable that I just have the project files VS, not generated.

+7
c ++ c windows visual-studio build
source share
5 answers
  • If you need to make a behavior and use it, you can create visual studio project projects and incorporate them into your project.

  • If you want less clunky, you can write visual studio macros and customize build events and bind them to specific build calls / hooks.

  • You can try something like workspacewhiz that allows you to set up environment variables for your project in a file format that can be registered. Then users can modify them locally.

+5
source share

I ran into this exact problem and I started working using custom build rules.

But it was always pain and worked badly. I left the visual studio and went with the Makefile system using cygwin. Much better now.

cl.exe is the name of the VS compiler.

Update. I recently switched to using cmake, which has its own problems, and cmake can create a visual studio solution. This seems to work well.

+4
source share

In particular, for # 3, I use property pages to indicate the location settings of third-party libraries (including paths, link paths, etc.). You can use custom macros from a parent or higher level property sheet to specify the starting point for the libraries themselves (if they are in a common root location), and then define separate sheets for each library using the base path macro. It is not automatic, but it is easy to maintain, and each developer can, if necessary, have a different root directory (he is in our environment).

One of the drawbacks of this approach is that the include paths constructed in this way are not included in the search paths for Visual Studio (unless you duplicate the definitions in the project and directory settings for VS). I talked with some people from MS in PDC08 about how this is fixed for VS2010, and improving the interface as a whole, but not from the solid promises of them.

+2
source share

(1) . I don't know a simple answer to this question, but there are workarounds:

1a. If the contents of the generated files do not collide (i.e. there are no common static identifiers, etc.), you can add one file to the project, such as AllGeneratedFiles.c, and modify the generator to add the # generated / file. c "to this file when creating the generated /file.c.

1b. Or you can create a separate makefile-based project for the generated files and build them with nmake.

(2) . Use a custom build rule instead of the post-build event. You can add your own build rule by right-clicking on the project name in Solution Explorer and selecting Custom Build Rules.

(3) . There is no standard way to do this; it should be determined on the basis of each project. One approach is to use environment variables to define external dependencies. Then you can use these environment variables in the project properties. Add a readme.txt file that describes the necessary tools and libraries and the corresponding environment variables that the user must set, and this should be easy enough for any user.

+1
source share

Depending on what you are trying to do, sometimes you might be lucky using the custom build step and setting up your dependencies correctly. It may be useful to put all the generated code in your own project, and then depend on your main project.

+1
source share

All Articles