Visual Studio pre-build action to skip project build based on condition - visual-studio

In a VS 2008 solution, I have several projects. I run the build on the entire solution with msbuild. Based on the existence of a file on the disk, I want to skip the build for one of the projects. How can I achieve this? Is there a way to use a prebuild action to skip the project build?

PreBuildEvent is used to call custom script in OutDir. There is no special flags to skip building. I know several ways to hack build system and get needed behaviour, but it's not cosher.
1) First of all you can create two solutions (with and without that project). On top of that you can easily create a script which will check existence of the file and call MSBuild to build one or another.
2) You can remove the project from sln, add new simple project (let's say dll) and check existence of the file in BeforeBuild action and call MSBuild to build your custom project. Or you can add this behaviour to the one of the projects in that sln.

Related

How to use default project output locations in TFS 2013 build definition?

I have a solution which has several VC++ projects. I am trying to make TFS do weekly builds. I have set up TFS Build controller and agent. I created a build definition using DefaultTemplate.xaml file and I can successfully build some of the projects.
The problem is my projects depend on some libraries that are already checked in to debug/release folders. TFS is trying to put project outputs (dlls and exes) to $(SolutionDir)\Binaries directory. Since dependent libraries don't exist on this location, TFS build fails.
What I would like to do is use my own project output locations and somehow copy the output files to somewhere in server.
How can I do that?
Thanks
It's not recommended checking in the libraries to TFS, you can use Nuget to restore the packages.
For the build outputs, you can specify the drop folder in your build definition and copy the outputs to the drop folder.
You can also check in a script that copy the outputs, and specify a post-build script path in your XAML build definition. This script gathers some of the typical binary types from the typical locations and copies them to the folder from which TFBuild copies and drops to your staging location. Check more information about Run a script in your XAML build process at website:
https://msdn.microsoft.com/library/dn376353%28v=vs.120%29.aspx
I would suggest to edit your build definition. Under Process section, set MSBuild arguments to
/p:GenerateProjectSpecificOutputFolder=true
As follows:

VS 2010 - Always execute pre-build event

In my solution I have a project with an attached pre-build event to check if certain files need to be regenerated. This all works fine if something changed in the project (or dependent projects). However, if nothing changed the pre-build event is not triggered.
Is there a way to run the pre-build event everytime VS tries to build a project (even if it is clean from a code file standpoint)?
Alternatively, is there any other way to run a script first before building a project so that I can regenerate my files first?
For a Visual C++ project you may specify Command Line in the Custom build step (Configuration Properties - Custom build step) and leave the field Outputs empty. It will be executed even if the project has no changes.
Here is the similar question.

Use Visual Studio solution in ci server or maintain a separate build file

What is common way of doing this?
Maintaining a separate build file (nant by example) costs time but Will not lock you in to Visual studio.
Do most developers build with the Visual studio solution or do they have to use the nant build file.
What are the best practices?
What I do is use the proj files rather than sln files. MSbuild processes them just fine.
This way you have the best of both worlds. You are not locked into VS, but you do not have to maintain 2 copies of your build files either
It depends on your project...
I have multiple solutions that i want to build as one product, so i use msbuild / nant to include them all.
Another reason to use a build file is when you have more actions you want to execute when the CI server builds the project and you don't want those actions to be executed when the developers build the solution (Copying files for deployment or setting assembly version for example)
In general, i think that unless you have a reason to use a build file, you can just use the sln file

add items to visual studio solution in msbuild task

I have created a msbuild task that minifies and combines javascript and css files that is triggered when my visual studio project is built.
This task adds the minified and combined files to the file system.
However I would like that they automatically be added into the visual studio project. Is this possible and if so, how can I achieve this?
I would recommend against doing this inside the default "Build" target of your project file -- IMO the Build target should be pristine and should do nothing but compile/build the project itself. It also can create headaches depending upon how and when your builds execute in your build lifecycle.
Instead, create a new MSBuild target in your build file which performs this addition for you. I hope you have a main build file outside your Visual Studio project -- this will make everything much easier. Since your CSProj file is just a simple XML (MSBuild) file, it's easy enough to write your own custom task which modified the project to add whatever files you like to it.

Visual Studio 2008 Post Build event -- only run on Rebuild

In Visual Studio 2008 we run a post build event which calls NANT and in turn creates our config files.
e.g.
if $(SolutionDir) == . GOTO end
nant -buildfile:$(SolutionDir)default.build create..web.config
Is there a way to run this only on ReBuild?
I think you can do this by specifying build targets rather than using build events. Try creating an AfterClean target to delete your generated config files, and a BeforeBuild target to create them. Make sure you set up the file dependency for the BeforeBuild target, so msbuild knows it should only run the step if the file isn't present.
I haven't actually tried this, but I beleive msbuild will only run the target if the target files don't exist. When you rebuild, the cleaning process will be invoked, and in turn your AfterClean target.
You can read more about build targets here. The only real downside to using build targets instead of events is that they are not visible anywhere in the VS UI - you will only find them if you inspect the project file.
There may be a more direct solution involving events - have look at the msbuild team blog here.

Resources