Adding and removing build targets from NuGet powershell

1. May 2013 15:56 by admin in .net, msbuild, nuget
In NuGet packages you can add powershell scripts to alter the .csproj file of the project in which your package is installed. Recently I had quote some trouble getting this exactly right but nailed it in the end. So here's a sample to share with google so I can find it later ;) This sample adds a target that runs after the AfterBuild target: The Get-Project and Get-MSBuildProject are from the nuget powertools by David Fowlder. (This script is part of the install.ps1 script from a open source project called Weld).

Adding a build target to a project

$project = Get-Project
$buildProject = Get-MSBuildProject
$target = $buildProject.Xml.AddTarget("WeldAfterbuild")
$target.AfterTargets = "AfterBuild"
$task = $target.AddTask("Exec")
$task.SetParameter("Command", "`".\..\packages\Weld.1.0.0\tools\Weld.console`" bin\`$(TargetFileName) `"`$(ProjectDir)\Scripts\Weld`"")
$project.Save() #persists the changes
Notice how the ` (backtick) is used to escape the " and $ characters. This result in the .csproj like this:
<Target Name="WeldAfterbuild" AfterTargets="AfterBuild">
<Exec Command="&quot;.\..\packages\Weld.1.0.0\tools\Weld.console&quot; bin\$(TargetFileName) &quot;$(ProjectDir)\Scripts\Weld&quot;" />
This effectively calls the Weld.Console application passing it the current project .dll name and a target folder.

Removing a build target from a project

In uninstall.ps1 we can remove the same target like this:
$project = Get-Project
$buildProject = Get-MSBuildProject
$projectRoot = $buildProject.Xml;
Foreach ($target in $projectRoot.Targets)
If ($target.Name -eq "WeldAfterbuild")
$project.Save() #persists the changes
Basically we search for target called "WeldAfterbuild" and then remove that from the project! Easy once you know how :)

Bella Drawhorn 9/7/2013 9:15:43 PM United States #
Bella Drawhorn

You have remarked very interesting details! ps nice internet site.

Robin Brecht 9/9/2013 7:43:11 PM United States #
Robin Brecht

Whats cheery very polite website!! Man .. Excellent .. Superb .. I'll bookmark your web position and acquire the feeds additionally...I am pleased to find many beneficial information here in the situate up, we'd like increase extra strategies in this regard, thank you for sharing. . . . . .

Handmade Jewelry 9/30/2013 7:47:22 PM United States #
Handmade Jewelry

Thanks for this post. I certainly agree with what you might be saying. I have been talking about this topic a lot lately with my father so hopefully this will get him to see my point of view. Fingers crossed!

Copper Jewelry 10/6/2013 11:14:45 PM United States #
Copper Jewelry

Absolutely   pent   topic matter,  regards  for  entropy.

Handmade Jewelry 10/8/2013 10:18:12 PM United States #
Handmade Jewelry

I’m impressed, I must say. Genuinely rarely can i encounter a blog that’s both educative and entertaining, and without a doubt, you've hit the nail on the head. Your concept is outstanding; the issue is something that too small individuals are speaking intelligently about. My business is quite pleased i always stumbled across this during my try to discover something regarding this.

Copper Jewelry 10/14/2013 2:01:08 AM United States #
Copper Jewelry

The excellent intreguing articles keep me coming back here time and time once more. thank you so considerably.

Handmade Jewelry 10/19/2013 1:16:59 AM United States #
Handmade Jewelry

Aw, this was a really good post. In thought I would like to place in writing in this way moreover - taking time and actual effort to create a quite good article… but what / things I say… I procrastinate alot and also no indicates apparently get something done.

Awesome Copper Earrings 10/29/2013 12:40:08 AM United States #
Awesome Copper Earrings

I  view  something  genuinely unique in this internet site  .

Copper Earrings 10/29/2013 9:07:17 PM United States #
Copper Earrings

My spouse and  I stumbled more than here by a different web address and thought I might check issues out. I like what I see so i'm just following you. Appear forward to checking out your internet page once more.

Fashionable Copper Earrings 10/30/2013 6:16:35 AM United States #
Fashionable Copper Earrings

You've got  remarked really interesting points ! ps good   web site  .

Handmade Jewelry 11/2/2013 4:37:21 AM United States #
Handmade Jewelry

Could it be okay to write several of this on my small internet site only incorporate a one way link to the internet site?

hostgator review 11/2/2013 2:40:50 PM United States #
hostgator review

Salut je peut esseyer votre serveur s.v.p.<br />Esque vous qver le bouquet meo merci

Handmade Jewelry 11/3/2013 1:44:10 AM United States #
Handmade Jewelry

Hello there! Great post! Please inform us when I will see a follow up!

Handmade Jewelry 11/3/2013 5:52:34 AM United States #
Handmade Jewelry

I cannot thank you fully for the blogposts on your web page. I know you placed plenty of time and effort into all of them and hope you know how considerably I appreciate it. I hope I will do precisely exactly the same for yet another individual at some point. Palm Beach Condos

Handmade Jewelry 11/10/2013 1:08:37 AM United States #
Handmade Jewelry

I want to start a weblog but would like to own the domain. Any suggestions how to go about this?.

Handmade Jewelry 11/11/2013 4:16:24 AM United States #
Handmade Jewelry

Hey there! Good stuff, please keep us posted when you post once more something like that!

Eagle Safety Products 11/12/2013 8:09:08 AM United States #
Eagle Safety Products

This has been the most effective blogposts that I have read. Now i'm simply interested in how smart you might be. Because of your own personal insite I was able to take your information and administer it to my challenge. Your own personal posting was the excellent solution to my very own demands. If anyone desires this kind of information I will be sure to tell them about your web page. I would personally also like to express to all your subscribers they are fortunate to get this type of info. I liked your post so much that I appreciated this, tweeted it, subscribed, and saved it to my favorite social bookmarking website just for later examining. Again, i want to thank you for assisting me with helping me solve my dilemma

Natividad Lamon 11/12/2013 11:07:56 AM United States #
Natividad Lamon

Widest selection of VPN Services:

Sammy Kopsho 11/12/2013 4:14:47 PM United States #
Sammy Kopsho

How can i see the old whatsapp profile picture of my friend ?! Do you know how ?

Preston Barco 11/20/2013 9:10:29 PM United States #
Preston Barco

I am often to blogging and i really appreciate your content. The article has really peaks my interest. I am going to bookmark your site and keep checking for new information.

anchor 11/28/2013 8:29:37 AM United States #

Another thing I have really noticed is the fact that for many people, below-average credit is the reaction of circumstances further than their control. As an example they may have already been saddled having an illness and as a consequence they have large bills for collections. Maybe it's due to a employment loss and the inability to go to work. Sometimes divorce or separation can truly send the funds in a downward direction. Thanks for sharing your opinions on this blog.

Santa letters 12/4/2013 4:30:03 AM United States #
Santa letters

Hello there! I know this is kinda off topic but I'd figured I'd ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa? My website goes over a lot of the same topics as yours and I feel we could greatly benefit from each other. If you happen to be interested feel free to shoot me an email. I look forward to hearing from you! Awesome blog by the way!

Santa Calls 12/5/2013 8:37:31 PM United States #
Santa Calls

Have you ever thought about publishing an e-book or guest authoring on other websites? I have a blog centered on the same topics you discuss and would love to have you share some stories/information. I know my visitors would appreciate your work. If you are even remotely interested, feel free to send me an email.

Call from Santa Clause 12/7/2013 2:38:09 AM United States #
Call from Santa Clause

My partner and I stumbled over here from a different website and thought I might check things out. I like what I see so now i am following you. Look forward to exploring your web page again.

Peggie 12/20/2013 2:14:23 AM United States #

I am not positive the place you are getting your info, however good topic. I must spend some time studying more or understanding more. Thanks for great info I was on the lookout for this info for my mission.

austin personal injury 1/1/2014 6:55:22 PM United States #
austin personal injury

Should you are using WordPress, to about arrive spam difficulty just set up plug-in contact Akismet.

Result: chosen nickname "myloba9"; success - posted to first encountered partition ""; 1/3/2014 1:59:40 AM United States #
Result: chosen nickname &quot;myloba9&quot;; success - posted to first encountered partition &quot;;;

> And if (as your anecdote suggests) those kids are magnet students from Kealing or maybe Fulmore, they're mostly white, to boot.

Leginsy 1/16/2014 1:00:18 PM United States #

I am glad to be  one of several visitors  on this great   internet site  (:,  appreciate it for  putting up.

Leginsy 1/16/2014 4:02:11 PM United States #

Utterly   pent   articles , Really enjoyed reading .

chat lines 2/4/2014 10:34:46 AM United States #
chat lines

You have mentioned very interesting details! ps decent website.

Ling 2/7/2014 4:51:36 AM United States #

I like what you have done here, please keep providing stella information.

@realmandydee 2/14/2014 3:04:36 AM United States #

Can I discuss this on my twitter feed?

diamond 2/23/2014 12:47:24 PM United States #

Nice task on providing the details, this was very valuable.

jewels advice 2/23/2014 7:29:02 PM United States #
jewels advice

I was looking into stumbled upon your post, and am happy I did, thanks

Katelyn 2/28/2014 9:58:56 PM United States #

Good to see that there are still informative blogs out here, thanks.

Marian 3/2/2014 1:04:55 AM United States #

I like what you have done here, please keep providing stella information.

Nidia 3/4/2014 5:58:31 AM United States #

Thanks for doing the ground work here, there's a lot to build on here, nice job.

Dierdre 3/5/2014 11:27:57 AM United States #

More info like this will be great, hope I can stop by again and use it.

princess cut 3/6/2014 1:54:00 AM United States #
princess cut

Nice finding your blog I have gain a lot from it

more info 3/12/2014 1:15:05 AM United States #
more info

I like this website it's a master piece! Glad I noticed this on google.

teeth whitening 3/22/2014 11:49:53 AM United States #
teeth whitening

There are a lot of blog sites online, I'm grateful I found yours today, keep it up.

Alvaro 4/2/2014 11:41:39 AM United States #

"wow, awesome article.Really looking forward to read more. Fantastic."

Clarence 4/2/2014 4:36:13 PM United States #

Impressive! And I�m not easily impressed � WOW, A BLUE CAR!

Chadwick 4/3/2014 1:49:47 AM United States #

Now, I'm going to do something I like to call the 'Compliment Sandwhich" Where I say something good, talk about where you need improvement, and then end with something good.

amor al arte 4/3/2014 2:38:06 AM United States #
amor al arte

"Great, thanks for sharing this article. Cool."

Alica 4/3/2014 5:24:43 AM United States #

Impressive! And I�m not easily impressed � WOW, A BLUE CAR!

In 4/3/2014 11:10:03 AM United States #

A big mountain of sugar is too much for one man. I can see now why God portions it out in those little packets.

Vivian 4/10/2014 10:03:56 PM United States #

Keep the posts coming it was useful

full report 5/2/2014 2:35:37 PM United States #
full report

I haven't checked in here for some time because I thought it was getting boring, but the last few posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend Smile

comprar una tablet consejos 5/4/2014 12:53:08 PM United States #
comprar una tablet consejos

I really liked your blog post. Much thanks again. Will read on...

tarjetas de credito visa 5/5/2014 7:36:20 PM United States #
tarjetas de credito visa

Really informative article.Really looking forward to read more. Fantastic. 5/5/2014 10:39:02 PM United States #

Great blog.Much thanks again. Really Cool. 5/6/2014 2:21:21 AM United States #

I really like and appreciate your post.Really thank you! Really Cool.

pop over 5/8/2014 2:42:42 PM United States #
pop over

Hiya very nice web site!! Man .. Beautiful .. Superb .. I'll bookmark your website and take the feeds also�I am happy to search out so many helpful info right here in the submit, we need work out extra strategies in this regard, thanks for sharing.

news 5/15/2014 8:14:54 PM United States #

I think  this  internet site   contains some  very   excellent   information for everyone. "The penalty of success is to be bored by the attentions of people who formerly snubbed you." by Mary Wilson Little.

Wiojtas 6/6/2014 8:20:49 PM United States #

Sprzedam komfortowy dom w okolicach lublina wiecej na

Fermin Gunnels 6/8/2014 11:21:11 PM United States #
Fermin Gunnels

This was a great read. Thank you for sharing it along with us! Nowadays the internet is full of poor content but there's no doubt that you simply spent a lot of time by editing these content articles. Again, thanks for your time as well as your efforts!

voyance immediate aujourd'hui 6/12/2014 5:56:55 PM United States #
voyance immediate aujourd&#39;hui

tirage horoscope par telephone perpignan<br/>Visiter le excellent site web : <a href="">voyance par telephone gratuite</a>

Acheter liquide ecigarette 6/14/2014 2:18:02 AM United States #
Acheter liquide ecigarette

Visiter mon superbe post : <a href=""></a><br/>;

Nutrition Vitrolles 6/14/2014 6:29:27 AM United States #
Nutrition Vitrolles

Decouvrir ce nouveau blog : <a href="">Nutritionniste La Ciotat</a><br/>

Consultation voyance gratuite 6/14/2014 10:08:14 PM United States #
Consultation voyance gratuite

logiciel tarot par mail de marseille<br/>Consulter mon magnifique site : <a href="">voyance par telephone gratuite</a>

Sauvegarde Externe 6/15/2014 10:45:22 PM United States #
Sauvegarde Externe

Voir mon superbe post : <a href="">Sauvegarde Backup</a><br/>

Voyance directement 6/16/2014 1:24:23 AM United States #
Voyance directement

voyance par telephone  perpignan<br/>Voir ce magnifique site : <a href="">voyance gratuite amour</a>

voyance : 6/16/2014 6:10:00 AM United States #
voyance :

voyance par telephone  nice<br/>Consulter notre superbe site : <a href="">voyance</a>;

voyance 6/16/2014 5:38:09 PM United States #

voyance par telephone en direct perpignan<br/>Consulter mon superbe site web : <a href="">voyance par telephone gratuite</a>

Pantofi Barbatesti 6/18/2014 12:43:44 PM United States #
Pantofi Barbatesti

Simply because I initially wrote in excess of MBT footwear at <strong><a href=""; title="Pantofi Barbatesti">Pantofi Barbatesti</a></strong>, a great deal is made up of modified regarding the manufacturer, and the inventor and founder incorporates still left the enterprise. Between legitimate prospective buyers, assessments of MBT sneakers are rather put together. If by yourself're taking into consideration a couple of MBT footwear, I strongly persuade by yourself in direction of additionally read through the suggestions remaining in just respond to towards the after written content, and converse towards your health care provider right before carrying any fashion of shoe that is thus substantially alternate towards what your self're made use of towards, or in the direction of deal with any model of soreness or situation.

Become Popular 6/19/2014 12:18:22 AM United States #
Become Popular

As soon as you stick to our guide, your personal Facebook profile will prosper. If you know what I mean.

Cena zestaw kamer 7/14/2014 3:10:21 PM United States #
Cena zestaw kamer

I have been exploring for a little bit for any high quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this web site. Reading this info So i�m happy to convey that I've an incredibly good uncanny feeling I discovered exactly what I needed. I most certainly will make sure to don�t forget this web site and give it a look on a constant basis.

Jarred 4/9/2015 9:39:21 AM United States #

Good day!<br />Others have voiced my confusion above, but it's nice sometimes to add to the melee. I have been signed up since the middle of January, but have three letters. They're fantastic letters! But similarly, I'd like to know if this is just the process of the dust settling or if this is to be expected?<br />Thanks!

Dropbox Tips Tricks 4/29/2015 4:30:10 AM United States #
Dropbox Tips Tricks

This website was... how do I say it? Relevant!! Finally I've found something that helped me. Thanks!

Tutorial optimizare texte site 5/3/2015 11:50:56 PM United States #
Tutorial optimizare texte site

Invata gratuit cum sa faci optimizare texte pentru site-ul tau! Am postat un filmuletr in care va explic despre cum ar trebui introduse textele in site ca site-ul dumneavoastra sa ajunga in prima pagina din Google garantat. Detalii pe

Hidroplasto 5/4/2015 5:51:53 PM United States #

Thanks designed for sharing such a pleasant thinking, paragraph is nice, thats why i have read it entirely|

Hidroplasto 5/4/2015 8:04:22 PM United States #

You need to be a part of a contest for one of the best websites online. I am going to highly recommend this website!|

Allen Mavel 5/8/2015 4:44:07 PM #
Allen Mavel

I have a solution that has 5 projects.  When I add a package using the script (very similar) from above.  It always changes the last csproj file in the solution not the one I'm targeting, but it does change the packages.config of the project I had selected.  

��C 5/15/2015 6:35:21 PM United States #

Top site, a bientot sur la toile

Evonne Figone 6/4/2015 9:34:20 AM United States #
Evonne Figone

Hey there! I know this is kinda off topic but I was wondering which blog platform are you using for this website? I'm getting fed up of Wordpress because I've had issues with hackers and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

Merry Cilva 6/6/2015 1:35:25 PM United States #
Merry Cilva

Do you mind if I quote a few of your posts as long as I provide credit and sources back to your blog? My blog is in the exact same area of interest as yours and my visitors would certainly benefit from some of the information you present here. Please let me know if this ok with you. Appreciate it!

Nanci Vincik 6/9/2015 12:30:52 PM United States #
Nanci Vincik

I am a long time in the past I study your blog and has long been expressing that you’re a great writer

Burton Haynes 6/9/2015 5:50:48 PM United States #
Burton Haynes

Czy mo�na upiec ciasto bez m�ki? Mo�na! A bez jajek? Te� mo�na! Ciasto powsta�o specjalnie dla mojej starszej c�ry, kt�ra ma uczulenie na bia�ko jaja kurzego i czeka na badanie w kierunku celiakii st�d te� od oko�o roku w naszym domu cz�stym go�ciem s� produkty bezglutenowe. Dodatkowo mamie zachcia�o si� zosta� wegank�, ale kocha smak czekolady, tato te� uwielbia s�odycze, m�odsza siostrzyczka te� ch�tnie li�nie, tak wi�c jest tou nas ciasto idealne dla ka�dego. No i przygotowuje si� je bez u�ycia miksera, bez brudzenia miliona gar�w i potrafi je przygotowa� (z ma�� pomoc�) moja 3-letnia c�rka. Tak�e serdecznie zach�cam do spr�bowania, bo naprawd� warto! Panie i Panowie: Czekoladowe, bezglutenowe vege-ciasto.Wi�cej informacji na moim blogu

bandar bola 6/20/2015 11:16:08 PM United States #
bandar bola

Zune and iPod: Most people compare the Zune to the Touch, but after seeing how slim and surprisingly small and light it is, I consider it to be a rather unique hybrid that combines qualities of both the Touch and the Nano. It's very colorful and lovely OLED screen is slightly smaller than the touch screen, but the player itself feels quite a bit smaller and lighter. It weighs about 2/3 as much, and is noticeably smaller in width and height, while being just a hair thicker.

tom 6/22/2015 5:37:20 AM United States #

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?

Marco 7/10/2015 3:58:08 AM United States #

Hi everybody, I'm an Italian man decided to send a message which will describe my personality. Long ago there were transmitted values by GOD and JESUS, and at that time people felt it more consideration. Nowadays, the observance of these principles has started a process of decay. This consideration of the values is not only vital in personal relationships between men and women, but also towards present and future society, which learns and will learns our behaviour patterns. All this means that the more time passes, the less importance has the lives of others. A couple must have a very strong faith in order to address all the problems that life delivers, so it is necessary that each other are offset by a fidelity that is based precisely on the concepts above. IT'S ESSENTIALS THAT ALL PEOPLE DIFFUSE THE GOSPEL ALL OVER THE WORLD AS MANY PEOPLE WE CAN. My main characteristic is focused on being God-loving, for this reason i'm very reliable in relationships. Nobody is perfect, but this particular side makes safer a person who is interested to become a part of my life. I am willing to start something special that will lead to the development of a more solid bond. I'm available to relocate everywhere because for me geographical distance is purely a matter of jumping on a plane and next second virtual world became reality. Whatsapp: +447937463555; Viber: +393409282577; skype: testifi87

free mp3 download 7/16/2015 11:30:11 AM United States #
free mp3 download

Free Music MP3 Downloader est un programme qui se charge de télécharger les fichiers MP3

free mp3 download 7/16/2015 12:37:06 PM United States #
free mp3 download

Free Music MP3 Downloader est un programme qui se charge de télécharger les fichiers MP3

free mp3 download 7/16/2015 3:20:40 PM United States #
free mp3 download

Download free MP3 songs from best music sites. Discover top 10 MP3 sites to find, preview & download free music

free mp3 download 7/16/2015 4:12:59 PM United States #
free mp3 download

Free Music MP3 Downloader est un programme qui se charge de télécharger les fichiers MP3

free mp3 download sites 7/16/2015 9:05:51 PM United States #
 free mp3 download sites

Search for your favorite songs in our MP3 database and download these in the best possible quality for free.

Jesusa Pernice 7/18/2015 3:02:21 PM United States #
Jesusa Pernice

Ex-NFL Player Mistress Murders Wife ... Cops (Update):

Marco 7/22/2015 2:38:15 AM United States #

According to the Bible, Adam and Eve were the first humans created by God, who lived approximately 6,000 years ago. According to the science, humans existed a long time before. The two lines of thought can be easily united, thanks to the omnipotence of God, who in the beginning created humans in a reality where there was no concept of "evil". Metaphorically speaking, Adam and Eve were expelled from this heavenly reality, find himself in another reality, namely in today's reality that we all know, where there is the concept of evil, as well as that of the well; not necessarily a reality where they were the first humans, but the first who experienced firsthand the life God had reserved for them (so they were the first humans in the "perfect" reality). From here it is clear that the story of Adam and Eve does not upset in the least bit the evolutionary linearity, and the seven days of creation relate to a creation took place in the reality of Adam and Eve, where everything was possible, even just create the stars, animals and everything else, without the scientific method and the time needed to have their share. In practice, they were the first men of God; whereas prehistoric man lived before Adam and Eve was a man, but it could be considered as an animal evolved from animals or created by something else, which had two arms and two legs, and that may have hybridazed with the descendants of Adam And Eve after they were "moved away" from the "perfect reality". God has endowed man about the concept of "infinity" and "eternity", as well as other questions can not be explained through the use of the scientific method, thus making humans free to believe in God or not, in a reality for us tricky and necessary for the construction and continuation of his project.

government solar rebate 7/23/2015 12:26:14 PM United States #
government solar rebate

Hello I just loves your amazing site thank you and pls keep the ball rolling

click through the following document 7/26/2015 7:02:24 AM United States #
click through the following document

I will not talk about your competence, the post simply disgusting

limited edition agua bendita 7/29/2015 3:23:55 AM United States #
limited edition agua bendita

Lucien Webbink 7/29/2015 11:44:57 PM United States #
Lucien Webbink

<p>Excellent read, I just passed this onto a colleague who was doing some research on that. And he actually bought me lunch since I found it for him smile So let me rephrase that: Thank you for lunch!</p>

addiction counselling dublin 7 7/30/2015 11:06:08 PM United States #
addiction counselling dublin 7

I have to come out and say that that this piece of writing is seriously helpful. I have spent most of my spare time looking through your content.  one word come to mind remarkable. Time enjoyed .Thanks A Lot  I bookmarked as a popular choice I plan to read more!

Rory Leatherman 8/6/2015 10:55:58 AM United States #
Rory Leatherman

Cary Mcsweeny 8/6/2015 2:05:25 PM United States #
Cary Mcsweeny

agua bendita bikini 8/6/2015 2:25:35 PM United States #
agua bendita bikini