Is there a Pre-Run event? - visual-studio-2010

Hey, I use a Pre-build event to call an external compiler to compile an opencl kernel. This way i get all the errors messages inside the ide. But if you only change the kernel, the compiler is not required to run so there is no pre-build event, even if the kernel compile command would generate an error. So is there a way to run the command before you execute your program instead? Like a Pre-Run event ;)

You can have your pre-build target add the item to the inputs list I think it is. Once Visual studio is clued in to check those files for modification, it will know to trigger your Target. I'm not sure that it will actually Invoke a pre-build, so you may want to hook into another target as a BeforeTargets attribute.
Your project file will typically have a Imports on some targets files, that should give you somewhere to start searching for which Target is appropriate.
Another possibility is to add your target to the default targets list at the top of the proj file.
how-to-invoke-the-same-msbuild-target-twice-with-different-parameters-from-within reference may help.

Related

Method to make IncludeDirs available to external tool

I'm currently trying to make splint available as an external tool in Visual Studio 2010.
It has problems with finding all includes for the file, since it seems that the INCLUDE variable is only set at build time and I haven't found any other possibility to extract the include files in any way.
My question: Would there be any way to extract the IncludeDir field from the current file's project's Properties page, ideally with the VC++'s AdditionalIncludeDirectories?
Note also that AdditionalIncludeDirectories is per file, as it can be changed for individual source files as well as on the project level, and if it contains macros it can evaluate differently for each source file too!
I'm not familiar with driving the MSBuild objects via the API, but that's used by the IDE. Whether that way or by simply running MSBuild.exe, you need to get it to figure out all the properties, conditions, etc. and then tell you the result. If everything is well behaved, you could create a target that also uses the ClCompile item array and emits the %(AdditionalIncludeDirectories) metadata somehow such as writing it to a file or passing it to your other tool somehow. That's what's used to generate the /I parameters to CL, and you can get the same values.
If things are not well behaved in that necessary values are changed during the detailed build process, you would need to get the same prelims done just like the ClCompile target normally does, too. Or just override ClCompile with your own (last definition of a target is used) so it certainly is in the same context.
Either way, there are places where build script files can be automatically included into all projects, so you can add your stuff there or use a command argument (I think) to MSBuild to add another Include.
—John

Run a process before compiling in Visual Studio C++

More exacly I want to run flex.exe "file.l" before compile to be able to compile lex.yy.c after. If there is anyway to do this? I mean do it automatically in a way I only click run and do all?
You may use Custom build steps
Check Project Properties->Build Events
The better solution is probably to add a custom build rule for .I files, so file2.I gets compiled as well. Additionally, pre-build steps run for every build, but custom build rules only run if the input file(s) changed.

How to make IBM Rational Developer for Power IDE retrieve error list automatically?

I am currently working on a task to exploit the iProject Remote Build functionality of Rational Developer for Power (RDP) IDE for AS/400 related objects. I am developing a customized compilation utility, which is a generic tool to compile different source members, e.g. RPGLE, CLLE, PF. It is a command which accepts the source member, the source file, the source library and the target library as parameters. It is going to compile the specified source member and place the created object into the target library. Inside it the actual compilation is done using QCMDEXC API, with the compilation command set up as input parameter. It works fine on AS/400. Now I need to make it work on RDP directly with iProject Remote Build capability. Meanwhile any error generated should be automatically loaded to the Error List view after the compilation. I am aware the fact that Option(*EVENTF) must be included in order to generate the event file. But how to make RDP load it? The compilation utility is a command called CPLOBJ. Using source member A in file B in library C to create object A in library D is something like this: CPLOBJ SERMBR(C/B/A) LIBRARY(D).
See if this old article helps: http://www.itjungle.com/fhg/fhg080404-story01.html
Basically, the link between RDP and the compiler is through the event file. The compiler won't produce an event file unless you tell it to. Most compiler commands allow OPTION(*EVENTF) which is how you tell the compiler to create an event file. Your custom compile command needs the same parameter. It must also have a SRCMBR() parameter. So your custom compile command will need to look something like this:
COMPILE SRCMBR(nnnnn) OPTION(*EVENTF)
...and it will pass these values on to the IBM compile command.
Because you are using QCMDEXC to execute the IBM compile command (the one that actually generates the event file) you will need an additional step. You need to tell RDP that the compile completed and the event file is ready. This happens by placing the event file library and member name in the local data area. The library name goes in columns 1-10 and the member name in 11-20.
It might be best to ask this question on midrange.com. There are members of the Rational development team on the list as well as others that know the inner workings of RDP.
It has worked for me automatically, I have a feeling there is something not setup right or your missing a PTF somewhere.

Pre-build event to run before any project in a solution is built

I have a little program I wrote to download all NuGet packages for a solution. I would like to setup a pre-build event that would run this program every time I build.
But I need it to run before the first project starts to build. I could look at what is currently building first, and put it on that project's pre-build event, but that is fairly brittle. Any time I add a new project or update references between projects, I would have to double check that the "first" building project is still the first one.
So, what I really need is a way to do this before any building really starts. I have heard of Visual Studio macros. But those are not something that gets checked in so I would prefer to not use those (but if that is my only option, I would use them).
You could try this: http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild.aspx
Unfortunately it only works called from the command line via MSBuild. Seems to be a design flaw that the behaviour is different and these events are not available via the IDE.
You could also modify your base MSBuild tasks to include the action based on a specific flag/file existence/solution name, but this is all sorts of evil.
Otherwise, you are pretty stuck with a prebuild on each project.
I call nuget install from the prebuild event for any project that uses nuget packages. It is smart enough to only download packages that have not already been downloaded.

VS2010 - add custom compiler for certain file extensions

I've written a command-line OpenCL compiler. I'd like to have VS compile my kernel source files using this whenever I build the C# project that includes them. I've looked around and found information and custom build tasks, custom tools, etc, but I haven't been able to get it to work correctly.
How can I tell VS to run my exe on the source files in the same way that it runs the c# compiler, etc for other files in the project?
I report errors from this tool by calling Console.Error.WriteLine(). This dutifully places the errors in the Output pane, where I can double-click them, taking me to the appropriate place in the .cl kernel source file. However, the errors don't appear in the VS error panel. ??
Alternatively, if anyone's aware of an existing OpenCL compiler - it's annoying to have to run the host application just to compile the kernel - I'd appreciate a link.
I've managed to get this working by adding a post-build step to the project options. However, I'd really prefer for this exe to be run for every *.cl file in the project.
Update I had neglected to include an error code when formatting my error messages. Correcting them to match any of the formats listed here took care of that issue. Still trying to figure out how to associate an exe with a given file extension, though.

Resources