469,950 Members | 2,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

MSBuild: Project level tasks from solution

Hi

I trying to master msBuild but have a problem. I have a solution that I
wish to build using msbuild but want to override BeforeBuild/AfterBuild
targets for each of the projects. I trying to avoid modifying the
common.targets etc and the individual project .sln files and just do it
within a solution proj.

One method I've tried, is to create the .proj file from the .sln file using
the msbuildemitsolution enviroment flag- base upon
http://www.sedodream.com/PermaLink,g...aa24bc7da.aspx
but I still cannot get the targets to be called when the
individual projects are built - I think is is because the projects are not
imported but are run via a <MSBuild Projects task
does anyone have an example how to do this? or point me in the right
direction

thanks
dan

Oct 6 '06 #1
3 6599
Have a look at my MSDN article Inside MSBuild at
http://msdn.microsoft.com/msdnmag/is...d/default.aspx
I think what you're looking for is in the section "Extending the Build
Processes"
Hope that helps

Sayed Ibrahim Hashimi
http://www.sedodream.com

"Danny" wrote:
Hi

I trying to master msBuild but have a problem. I have a solution that I
wish to build using msbuild but want to override BeforeBuild/AfterBuild
targets for each of the projects. I trying to avoid modifying the
common.targets etc and the individual project .sln files and just do it
within a solution proj.

One method I've tried, is to create the .proj file from the .sln file using
the msbuildemitsolution enviroment flag- base upon
http://www.sedodream.com/PermaLink,g...aa24bc7da.aspx
but I still cannot get the targets to be called when the
individual projects are built - I think is is because the projects are not
imported but are run via a <MSBuild Projects task
does anyone have an example how to do this? or point me in the right
direction

thanks
dan

Oct 6 '06 #2
Hi Sayed

Great article, although I can't quite get what I want to work. Instead
working with a .sln file I tried it linking in another .csproj file to try
and override the BuildDependson property as described in your artical.
Below is the .proj if you can give it a quick scan with an experts eye (
it's a cut down version of my original .sln version).

As you can see am trying to override the build properties and call a custom
before build target- but it don't work...

I really appreciate your help thanks.

Dan

<!--================================================== =====================================

MSBuild file which can be used to inject steps into the building of solution
files

================================================== =========================================-->

<Project DefaultTargets="BuildSolution"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildSolutionDir>c:\devtest\</BuildSolutionDir>

</PropertyGroup>
<ItemGroup>

<!-- Item for solutions file(s) -->

<SlnFiles Include="$(BuildSolutionDir)*.csproj"/>

</ItemGroup>
<Target Name="BuildSolution" >

<!-- Have MSBuild emit the solution -->
<!-- Create a new item to pick up the newly generated file -->

<CreateItem Include="$(BuildSolutionDir)*.csproj">

<Output TaskParameter="Include" ItemName="SolutionMSBuildFiles"/>

</CreateItem>
<!--

Call MSBuild for each solution file. Pass the property:

theSolution=SOLUTION_FILE_TO_BUILD.

In the DoBuildSolution we use this to determine which file to build.

-->
<MSBuild Projects="$(MSBuildProjectFile) "

Targets="DoBuildSolution"

Properties="@(SolutionMSBuildFiles->'theSolution=$(BuildSolutionDir)%(Filename)%(Exte nsion)')"/>

</Target>

<PropertyGroup>

<DoBuildSolutionDependsOn>

BeforeDoBuildSolution;

CoreBuildSolution;

AfterDoBuildSolution

</DoBuildSolutionDependsOn>

</PropertyGroup>

<Target Name="DoBuildSolution"
DependsOnTargets="$(DoBuildSolutionDependsOn)" />
<Target Name="BeforeDoBuildSolution">

<Message Text="**************Before building your solution*****************"
Importance="high"/>

</Target>

<!--

Here is where we actually build the solution passed to us.

-->

<Target Name="AfterDoBuildSolution">

<Message Text="##############After building your solution##################"
Importance="high"/>

</Target>

<PropertyGroup>

<BuildDependsOn>

CustomBeforeBuild;

$(BuildDependsOn);

</BuildDependsOn>

</PropertyGroup>

<Target Name="CustomBeforeBuild">

<Message
Text="!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!CustomBeforeBuild!!"
Importance="high"></Message>

</Target>

<Target Name="CoreBuildSolution" >

<MSBuild Projects="$(theSolution)" Targets="Build"/>

</Target>

</Project>

"Sayed Ibrahim Hashimi" <Sa*****************@discussions.microsoft.com>
wrote in message news:DE**********************************@microsof t.com...
Have a look at my MSDN article Inside MSBuild at
http://msdn.microsoft.com/msdnmag/is...d/default.aspx
I think what you're looking for is in the section "Extending the Build
Processes"
Hope that helps

Sayed Ibrahim Hashimi
http://www.sedodream.com

"Danny" wrote:
>Hi

I trying to master msBuild but have a problem. I have a solution that I
wish to build using msbuild but want to override BeforeBuild/AfterBuild
targets for each of the projects. I trying to avoid modifying the
common.targets etc and the individual project .sln files and just do it
within a solution proj.

One method I've tried, is to create the .proj file from the .sln file
using
the msbuildemitsolution enviroment flag- base upon
http://www.sedodream.com/PermaLink,g...aa24bc7da.aspx
but I still cannot get the targets to be called when the
individual projects are built - I think is is because the projects are
not
imported but are run via a <MSBuild Projects task
does anyone have an example how to do this? or point me in the right
direction

thanks
dan


Oct 8 '06 #3
Hi,
Are you trying to make something happen before a project is built or before
the solution is built? If you need it to happen before a project, then you
should place your changes in the actual .csproj file (after the Import
statement). If you want it to happen before the solution that you are trying
to build, then simply put the tasks to execute before you call use the
MSBuild task to build the solution. If you are trying to perform the
before/after steps for the entire solution file, what you provided previously
may be overly complicated for this specific scenario. You should be able to
achieve it with something more similar to what is shown below.

<Project DefaultTargets="BuildSolution"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildSolutionDir>c:\devtest\</BuildSolutionDir>
</PropertyGroup>

<ItemGroup>
<!-- Item for solutions file(s) -->
<SlnFiles Include="$(BuildSolutionDir)*.sln"/>
</ItemGroup>

<Target Name="BuildSolution" >
<!-- Perform your before build steps here -->

<MSBuild Projects="@(SlnFiles)" Targets="Build" />

<!-- Perform your After build steps here-->
</Target>
</Project>
HTH,
Sayed Ibrahim Hashimi
www.sedodream.com

"Danny" wrote:
Hi Sayed

Great article, although I can't quite get what I want to work. Instead
working with a .sln file I tried it linking in another .csproj file to try
and override the BuildDependson property as described in your artical.
Below is the .proj if you can give it a quick scan with an experts eye (
it's a cut down version of my original .sln version).

As you can see am trying to override the build properties and call a custom
before build target- but it don't work...

I really appreciate your help thanks.

Dan

<!--================================================== =====================================

MSBuild file which can be used to inject steps into the building of solution
files

================================================== =========================================-->

<Project DefaultTargets="BuildSolution"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildSolutionDir>c:\devtest\</BuildSolutionDir>

</PropertyGroup>
<ItemGroup>

<!-- Item for solutions file(s) -->

<SlnFiles Include="$(BuildSolutionDir)*.csproj"/>

</ItemGroup>
<Target Name="BuildSolution" >

<!-- Have MSBuild emit the solution -->
<!-- Create a new item to pick up the newly generated file -->

<CreateItem Include="$(BuildSolutionDir)*.csproj">

<Output TaskParameter="Include" ItemName="SolutionMSBuildFiles"/>

</CreateItem>
<!--

Call MSBuild for each solution file. Pass the property:

theSolution=SOLUTION_FILE_TO_BUILD.

In the DoBuildSolution we use this to determine which file to build.

-->
<MSBuild Projects="$(MSBuildProjectFile) "

Targets="DoBuildSolution"

Properties="@(SolutionMSBuildFiles->'theSolution=$(BuildSolutionDir)%(Filename)%(Exte nsion)')"/>

</Target>

<PropertyGroup>

<DoBuildSolutionDependsOn>

BeforeDoBuildSolution;

CoreBuildSolution;

AfterDoBuildSolution

</DoBuildSolutionDependsOn>

</PropertyGroup>

<Target Name="DoBuildSolution"
DependsOnTargets="$(DoBuildSolutionDependsOn)" />
<Target Name="BeforeDoBuildSolution">

<Message Text="**************Before building your solution*****************"
Importance="high"/>

</Target>

<!--

Here is where we actually build the solution passed to us.

-->

<Target Name="AfterDoBuildSolution">

<Message Text="##############After building your solution##################"
Importance="high"/>

</Target>

<PropertyGroup>

<BuildDependsOn>

CustomBeforeBuild;

$(BuildDependsOn);

</BuildDependsOn>

</PropertyGroup>

<Target Name="CustomBeforeBuild">

<Message
Text="!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!CustomBeforeBuild!!"
Importance="high"></Message>

</Target>

<Target Name="CoreBuildSolution" >

<MSBuild Projects="$(theSolution)" Targets="Build"/>

</Target>

</Project>

"Sayed Ibrahim Hashimi" <Sa*****************@discussions.microsoft.com>
wrote in message news:DE**********************************@microsof t.com...
Have a look at my MSDN article Inside MSBuild at
http://msdn.microsoft.com/msdnmag/is...d/default.aspx
I think what you're looking for is in the section "Extending the Build
Processes"
Hope that helps

Sayed Ibrahim Hashimi
http://www.sedodream.com

"Danny" wrote:
Hi

I trying to master msBuild but have a problem. I have a solution that I
wish to build using msbuild but want to override BeforeBuild/AfterBuild
targets for each of the projects. I trying to avoid modifying the
common.targets etc and the individual project .sln files and just do it
within a solution proj.

One method I've tried, is to create the .proj file from the .sln file
using
the msbuildemitsolution enviroment flag- base upon
http://www.sedodream.com/PermaLink,g...aa24bc7da.aspx
but I still cannot get the targets to be called when the
individual projects are built - I think is is because the projects are
not
imported but are run via a <MSBuild Projects task
does anyone have an example how to do this? or point me in the right
direction

thanks
dan



Oct 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joshua Flanagan | last post: by
5 posts views Thread by Al | last post: by
2 posts views Thread by Jonathan Kacprowicz | last post: by
reply views Thread by luvic.vangool | last post: by
1 post views Thread by Shikhar | last post: by
3 posts views Thread by shapper | last post: by
7 posts views Thread by shapper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.