If I have a solution with multiple projects in it, and I call (from the command line):
MSBuild xxx.sln
I know that it will start building each of projects in the solution.
My question is: is there a way to make a task run only once, say with the first project keep in mind that I do not know which is the first one, meaning it has to dynamic.

Excute a task once per solution.
Madhurima
Here's another idea, wrap your task into a target let's call this target GetLatest. Then place this target into the InitialTargets list of your project like:
<Project InitialTargets="GetLatest" ..
This gives you:
1) You know it executes before any other targets, because it's in the InitialTargets list
2) You know it will execute only once, because MSBuild will skip targets that have already executed
3) This works when build solution file as well
Sayed Ibrahim Hashimi
www.sedodream.com
Malini
Hi,
Is this a custom task or a task which shipps with MSBuild
Thanks
Jay
Tahoo
PALANISELVAM
There are a few ways I can see you doing this.
1. If you don't care about this task being exeucted within VS, but is something that you want to do as a part of your daily build on a build machine for example, you can do this by having a wrapper project that builds your solution. The wrapper project - let's call it build.proj can invoke the solution like this, using the MSBuild task:
<MSBuild Projects="my.sln" />
This way, you can do any custom steps you want to do once per solution before and after the MSBuild task.
2. Another way to achieve the same thing would be to customize the solution wrapper project that MSBuild creates when you invoke msbuild from the command line. You can get msbuild to save out this file for you by setting an environment variable called MSBuildEmitSolution = 1. When you build my.sln from the command line after this, you should see my.sln.proj that is an msbuild project that represents the solution. You can then customize this project so that your task is called once before any project builds. Also, keep in mind that this file is generated everytime by MSBuild - so you will need to refresh it to add any changes that have occurred to the solution in terms of new projects, etc.
3. Finally, you can edit all your projects to conditionally run the task - I think this is the only way to go if you want to run this task conditionally at design-time in the IDE.
If you want to do this purely for the build lab, I would recommend option 1 as it requies the least maintenance and is truly in line with the way MSBuild was designed to be used.
Hope this helps.
Faisal Mohamood
Program Manager - MSBuild
RaeYoung
That's right once per project. If you wanted to perform some customizations on the solution level you could write a wrapper proj file that could achieve this. Its pretty confusing though, I've written up about how to do this at: Use MSBuild to build Solution files.
Sayed Ibrahim Hashimi
www.sedodream.com
Jdlee
Since you have multiple projects and you need to dynamically determine which project should execute the task (and once executed the task should not execute again) -
are there any properties that can be examined to determine if the task should be executed or not. If so than you can have a condition on the task. In addition to this you can also create a static bool in the task and set it to true the first time and skip if it is true. This will ensure that the task logic in Execute will only get run once.
If you can send me some additional information on how and when the task should be invoked then I can try to see if there are other options.
Olmann
but it would execute once for each project, not once per solution, right
Best regards!
Yachtsman