Is there a way to conditionally run Visual Studio Post Build Steps - visual-studio

What we are looking for is: while compiling the same configuration, say Release|Win32, is there a way to only do the postbuild steps sometimes. Like, if I am on a dev machine do all the post-build steps or if I am on a build server then don't do them. Or is the only way to accomplish this is by implementing a new configuration?
Commenters: Thanks for the ideas, we do not want to use scripts as they would be one more thing to maintain, and going to MSBuild proj files would be a lot of headache at this point as well. Thanks for trying though.

You could use environment variables in the post build script. Something like this:
if NOT %ComputerName% == DEVMACHINENAME GOTO end
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ngen "$(TargetPath)"
:end

If you want to crack into MSBuild itself (.*proj files are essentially just MSBuild scripts), you can run machine-specific steps post-build: http://flimflan.com/blog/MachineSpecificTasksWithMSBuild.aspx
"This takes advantage of the fact that all environment variables are immediately available as properties in an MSBuild script; and that all Windows machines (that I've worked on recently) have the COMPUTERNAME environment variable set."

Would it be possible to implement your post build steps as an external script which is always executed, but has logic to conditionally perform the steps you require?

If you don't like to have a separate build configuration (which I think would make most sense) you could e.g. define an environment variable on your build server which you then can test for in you post-build script.

Related

Customizing Auto-Build for multiple C++-Projects

Hy guys,
for a project at the university we're faced with the following problem:
For coverage analysis purposes we should instrument the code of several C++-Projects, which are automatically build via a VBScript using devenv. Before the actual build process we have to add 3 things:
A new VC++-Directory, with the path to the Cl-Wrapper.exe which does the instrumentation (needs to be first entry).
Additional command line commands for the C\C++-Compiler.
Additional command line commands for the Linker.
We tried to solve this via an Add-In, launched through the /Command switch for devenv. Sadly this doesn't work. After a little search, we found thats MSBuild might solve our problem via an additional configuration. For me it looks like that this could be done only for a certain project. But we are looking for a project independent way to execute the 3 stepa above before the build process.
Is there any possibility to achieve this with devenv/MSBuild?
Thanks so far..

Indirect way to reference "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\datasvcutil.exe" in a prebuild event

I am running the datasvcutil.exe command in a prebuild event.
datasvcutil.exe is located in "C:\Windows\Microsoft.NET\Framework64\v4.0.30319" (on 64 bit machines.)
I can just hard code this as C:\Windows\Microsoft.NET\Framework64\v4.0.30319\datasvcutil.exe, but that seems rather brittle. When a hypothetical .net v4.0.30320 comes out my prebuild event will not work anymore.
With the Visual Studio Command prompt, I can call datasvcutil.exe with out the path. I am wondering if there is a similar indirect way to call this from my pre-build event command line.
Since the tool you need is in the same path as MSBuild.exe you could simply reference it with $(MSBuildBinPath)\DataSvcUtil.exe which would make it also independent of Framework / Framework64
I like Filburts answer above. But if you really want to be courageous, you can invoke:
%VS100COMNTOOLS%\VCVarsQueryRegistry.bat
rem and query one of the %FrameworkDIR32% or %FrameworkDIR64% environment variables, depending on your choice
If you are even more courageous, MSBuild is capable of reading registry by itself - the following link may help: http://msdn.microsoft.com/en-us/library/ms171458.aspx (check the "Registry Properties" section)

Using T4MVC with build script

Has anyone gotten T4MVC to run as part of a build script ? Preferably a NAnt build script.
I'd like to not have to check in the generated files and just have the build server create them as part of the build, but T4MVC will only run inside of Visual Studio.
I've tried:
http://devtalk.dk/2010/03/11/How+To+Run+T4MVC+On+Build.aspx
http://otac0n.com/blog/2010/12/23/Pain-Free-T4MVC.aspx
Has anyone successfully gotten a solution to work ?
I don't think you'll be able to make this work. T4MVC relies heavily on the DTE object model, and that simply is not available outside of VS.

Pass Custom Build Step variables to batch script in Visual Studio

Is there a way to make sure that all of the environment variables from MSBuild are propagated to the batch scripts that I am calling from my custom build steps? It would be really nice to use variables like %CONFIGURATION% and %TARGETPATH% in the batch files...
Not OOTB - you'll see lots of cases where chaining of build steps selectively whitelists batches of e.g. 50 parameters.
The problem is that 'properties' ion MSBuild includes variables, input environment variables and much more, which would quickly overflow the OS limits (and sensible maximums) on environment size.
You could whack a pile of SETs together with a WriteLinesToFile and/or invoke a batch file tha has such SET statements.
Another approach, if you're using 4.0 is to use the PowerShell task to create a cusotm script inline and execute it.

Is it possible to start an external program from the target directory when debugging?

When debugging I need to start an external program from the target directory of a build and am wondering if it can be accomplished using relative paths.
As a post-build event I have the following:
IF NOT "$(ConfigurationName)"=="Debug" GOTO End
:CopyExecutable
copy "$(SolutionDir)\Source\Lib\MyExecutable.exe" "$(TargetDir)"
:End
I need to run MyExecutable.exe when I am debugging so in the debug tab for the project properties I set "Start external program" to MyExecutable.exe but get a failure when running the debug. It seems I need to put the full path for this to work.
Is there a way to do this using relative paths?
The 'Start External Program' path is relative to your solution directory (in VS2005 anyway). So you could just put:
Source\Lib\MyExecutable.exe
I see you asked this a while ago, but I just ran into the same problem, and this is how I solved it.
(_Disclaimer: all directions are based on VS08. Things may be in different places in prior or future versions)
I get the feeling that your other program is not a post-build step you need to run before debugging, but rather a program that also needs to run (a server or something) aswell while you debug.
Use an empty C++ Make-File project (you can use other project types, but this one by default does no actual building, so I find it's the easiest), and alter its start-up properties (Project/Properties -> Debug) to run your other application. Then, set your solution to start multiple projects (Solution/Properties -> Common Properties -> Startup Project).
Did you try something like $(TargetDir)\..\Lib ?

Resources