473,594 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 msbuildemitsolu tion 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 6828
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 msbuildemitsolu tion 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= "BuildSolut ion"
xmlns="http://schemas.microso ft.com/developer/msbuild/2003">
<PropertyGrou p>
<BuildSolutionD ir>c:\devtest\</BuildSolutionDi r>

</PropertyGroup>
<ItemGroup>

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

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

</ItemGroup>
<Target Name="BuildSolu tion" >

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

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

<Output TaskParameter=" Include" ItemName="Solut ionMSBuildFiles "/>

</CreateItem>
<!--

Call MSBuild for each solution file. Pass the property:

theSolution=SOL UTION_FILE_TO_B UILD.

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

-->
<MSBuild Projects="$(MSB uildProjectFile ) "

Targets="DoBuil dSolution"

Properties="@(S olutionMSBuildF iles->'theSolution=$ (BuildSolutionD ir)%(Filename)% (Extension)')"/>

</Target>

<PropertyGrou p>

<DoBuildSolutio nDependsOn>

BeforeDoBuildSo lution;

CoreBuildSoluti on;

AfterDoBuildSol ution

</DoBuildSolution DependsOn>

</PropertyGroup>

<Target Name="DoBuildSo lution"
DependsOnTarget s="$(DoBuildSol utionDependsOn) " />
<Target Name="BeforeDoB uildSolution">

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

</Target>

<!--

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

-->

<Target Name="AfterDoBu ildSolution">

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

</Target>

<PropertyGrou p>

<BuildDependsOn >

CustomBeforeBui ld;

$(BuildDependsO n);

</BuildDependsOn>

</PropertyGroup>

<Target Name="CustomBef oreBuild">

<Message
Text="!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!Cu stomBeforeBuild !!"
Importance="hig h"></Message>

</Target>

<Target Name="CoreBuild Solution" >

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

</Target>

</Project>

"Sayed Ibrahim Hashimi" <Sa************ *****@discussio ns.microsoft.co m>
wrote in message news:DE******** *************** ***********@mic rosoft.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.targe ts 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 msbuildemitsolu tion 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= "BuildSolut ion"
xmlns="http://schemas.microso ft.com/developer/msbuild/2003">
<PropertyGrou p>
<BuildSolutionD ir>c:\devtest\</BuildSolutionDi r>
</PropertyGroup>

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

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

<MSBuild Projects="@(Sln Files)" 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= "BuildSolut ion"
xmlns="http://schemas.microso ft.com/developer/msbuild/2003">
<PropertyGrou p>
<BuildSolutionD ir>c:\devtest\</BuildSolutionDi r>

</PropertyGroup>
<ItemGroup>

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

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

</ItemGroup>
<Target Name="BuildSolu tion" >

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

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

<Output TaskParameter=" Include" ItemName="Solut ionMSBuildFiles "/>

</CreateItem>
<!--

Call MSBuild for each solution file. Pass the property:

theSolution=SOL UTION_FILE_TO_B UILD.

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

-->
<MSBuild Projects="$(MSB uildProjectFile ) "

Targets="DoBuil dSolution"

Properties="@(S olutionMSBuildF iles->'theSolution=$ (BuildSolutionD ir)%(Filename)% (Extension)')"/>

</Target>

<PropertyGrou p>

<DoBuildSolutio nDependsOn>

BeforeDoBuildSo lution;

CoreBuildSoluti on;

AfterDoBuildSol ution

</DoBuildSolution DependsOn>

</PropertyGroup>

<Target Name="DoBuildSo lution"
DependsOnTarget s="$(DoBuildSol utionDependsOn) " />
<Target Name="BeforeDoB uildSolution">

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

</Target>

<!--

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

-->

<Target Name="AfterDoBu ildSolution">

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

</Target>

<PropertyGrou p>

<BuildDependsOn >

CustomBeforeBui ld;

$(BuildDependsO n);

</BuildDependsOn>

</PropertyGroup>

<Target Name="CustomBef oreBuild">

<Message
Text="!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!Cu stomBeforeBuild !!"
Importance="hig h"></Message>

</Target>

<Target Name="CoreBuild Solution" >

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

</Target>

</Project>

"Sayed Ibrahim Hashimi" <Sa************ *****@discussio ns.microsoft.co m>
wrote in message news:DE******** *************** ***********@mic rosoft.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 msbuildemitsolu tion 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2058
by: Uma Abhyankar | last post by:
Hello All, I was facing an issue with VCBuild on Beta1. Today after shifting to .NET Beta2, it looks like the issue is still not resolved :-( I have to invoke VCBuild through MSBuild on command prompt. I have following issue: Issue: -------- MSBuild can invoke VCBuild internally. However it invokes VCBuild without
1
1701
by: Joshua Flanagan | last post by:
First, if there is a more appropriate newsgroup for MSBUILD questions, please let me know. I am trying to figure out how to create an item group that is evaluated AFTER some tasks have already run. For example, the build file will create a folder, and then copy various files into that folder. I then want a task to do something with all of the files in that folder. The way I currently have it setup will not work. I define a folder:...
5
4459
by: Al | last post by:
Hi all We have created a xml file that imports a single project using the Import element. This project compiles to a class library, but has references to two other projects that are also class libraries. We are having a path reference issue for the depending projects; if the build is started in another directory than that of the imported project. (It's a simple cannot find project xyz.csproj, build fails.) If we place the xml file in...
2
8148
by: Jonathan Kacprowicz | last post by:
I am trying to create a build process using MSBuild that will build my multiple projects all with the same AssemblyVersion and AssemblyFileVersion. I have tried using the AssemblyInfo task from the community tasks projects (http://msbuildtasks.tigris.org/) and the AssemblyInfoTask from the MSBuild blog (http://www.gotdotnet.com/codegallery/codegallery.aspx?id=93d23e13-c653-4815-9e79-16107919f93e). My scenario is this: I have several...
0
2543
by: luvic.vangool | last post by:
Hi, I am getting the MSB3422 exception when trying to build a solution with MSBuild. Basically one of the dependencies is a C++ project which is not found when resolving references. The exception says: "The project is either missing from disk or access was denied" I have checked the security permissions - and it all looks fine -
1
6365
by: Shikhar | last post by:
Hi All, I am new to VSTS and MS Build. I want to do a Zip (As in NANT) in MSBUILD proj file. Can anyone please help me in this. Also i want to create labels in Team Foundation Server (for all build files) before building it.
4
3349
by: ramshankaryadav | last post by:
Hi, I'm facing a problem while building a project through MSBuild, this project is a part of a solution which has several other projects on which it depends, but I want to build this project without building it's dependencies. We can do this for a solution by unselecting projects through Configuration Manager under solution properties, but how to achive same for a project!
3
1343
by: shapper | last post by:
Hello, I am working on an ASP.MET MVC Web Application with NET 3.5 in VS 2008. I need to run some extra tasks on this project build so I download MSBuild from http://msbuildtasks.tigris.org/. I installed it but no new project type shows in my VS 2008.
7
2410
by: shapper | last post by:
Hello, I am working on an ASP.MET MVC Web Application with NET 3.5 in VS 2008. I need to run some extra tasks on this project build so I download MSBuild from http://msbuildtasks.tigris.org/. I installed it but no new project type shows in my VS 2008.
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7877
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8253
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8009
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5411
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3867
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.