Adding and removing build targets from NuGet powershell

1. mei 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;" />
</Target>
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")
{
$projectRoot.RemoveChild($target);
}
}
$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 7-9-2013 21:15:43 United States #
Bella Drawhorn

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

Robin Brecht 9-9-2013 19:43:11 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 30-9-2013 19:47:22 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 6-10-2013 23:14:45 United States #
Copper Jewelry

Absolutely   pent   topic matter,  regards  for  entropy.

Handmade Jewelry 8-10-2013 22:18:12 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 14-10-2013 02:01:08 United States #
Copper Jewelry

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

Handmade Jewelry 19-10-2013 01:16:59 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 29-10-2013 00:40:08 United States #
Awesome Copper Earrings

I  view  something  genuinely unique in this internet site  .

Copper Earrings 29-10-2013 21:07:17 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 30-10-2013 06:16:35 United States #
Fashionable Copper Earrings

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

Handmade Jewelry 2-11-2013 04:37:21 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 2-11-2013 14:40:50 United States #
hostgator review

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

Handmade Jewelry 3-11-2013 01:44:10 United States #
Handmade Jewelry

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

Handmade Jewelry 3-11-2013 05:52:34 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 10-11-2013 01:08:37 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 04:16:24 United States #
Handmade Jewelry

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

Eagle Safety Products 12-11-2013 08:09:08 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 12-11-2013 11:07:56 United States #
Natividad Lamon

Widest selection of VPN Services: www.intl-alliance.com/.../index.php

Sammy Kopsho 12-11-2013 16:14:47 United States #
Sammy Kopsho

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

Preston Barco 20-11-2013 21:10:29 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 28-11-2013 08:29:37 United States #
anchor

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 4-12-2013 04:30:03 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 5-12-2013 20:37:31 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 7-12-2013 02:38:09 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 20-12-2013 02:14:23 United States #
Peggie

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 18:55:22 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 "http://www.bikeleague.org/content/now-president-keynote-womens-forum"; 3-1-2014 01:59:40 United States #
Result: chosen nickname &quot;myloba9&quot;; success - posted to first encountered partition &quot;http://www.bikeleague.org/content/now-president-keynote-womens-forum&quot;;

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

Leginsy 16-1-2014 13:00:18 United States #
Leginsy

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

Leginsy 16-1-2014 16:02:11 United States #
Leginsy

Utterly   pent   articles , Really enjoyed reading .

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

You have mentioned very interesting details! ps decent website.

Ling 7-2-2014 04:51:36 United States #
Ling

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

@realmandydee 14-2-2014 03:04:36 United States #
@realmandydee

Can I discuss this on my twitter feed?

diamond 23-2-2014 12:47:24 United States #
diamond

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

jewels advice 23-2-2014 19:29:02 United States #
jewels advice

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

Katelyn 28-2-2014 21:58:56 United States #
Katelyn

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

Marian 2-3-2014 01:04:55 United States #
Marian

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

Nidia 4-3-2014 05:58:31 United States #
Nidia

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

Dierdre 5-3-2014 11:27:57 United States #
Dierdre

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

princess cut 6-3-2014 01:54:00 United States #
princess cut

Nice finding your blog I have gain a lot from it

more info 12-3-2014 01:15:05 United States #
more info

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

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

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

Alvaro 2-4-2014 11:41:39 United States #
Alvaro

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

Clarence 2-4-2014 16:36:13 United States #
Clarence

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

Chadwick 3-4-2014 01:49:47 United States #
Chadwick

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 3-4-2014 02:38:06 United States #
amor al arte

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

Alica 3-4-2014 05:24:43 United States #
Alica

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

In 3-4-2014 11:10:03 United States #
In

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 10-4-2014 22:03:56 United States #
Vivian

Keep the posts coming it was useful

full report 2-5-2014 14:35:37 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 4-5-2014 12:53:08 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 19:36:20 United States #
tarjetas de credito visa

Really informative article.Really looking forward to read more. Fantastic.

http://productos-bancarios.com/ 5-5-2014 22:39:02 United States #
 http://productos-bancarios.com/

Great blog.Much thanks again. Really Cool.

http://productos-bancarios.com 6-5-2014 02:21:21 United States #
 http://productos-bancarios.com

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

pop over 8-5-2014 14:42:42 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 15-5-2014 20:14:54 United States #
news

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 20:20:49 United States #
Wiojtas

Sprzedam komfortowy dom w okolicach lublina wiecej na ogloszenia-lubelskie.pl/.../

Fermin Gunnels 8-6-2014 23:21:11 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 12-6-2014 17:56:55 United States #
voyance immediate aujourd&#39;hui

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

Acheter liquide ecigarette 14-6-2014 02:18:02 United States #
Acheter liquide ecigarette

Visiter mon superbe post : <a href="http://medicalcybrarian.com">http://www.medicalcybrarian.com</a><br/>;

Nutrition Vitrolles 14-6-2014 06:29:27 United States #
Nutrition Vitrolles

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

Consultation voyance gratuite 14-6-2014 22:08:14 United States #
Consultation voyance gratuite

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

Sauvegarde Externe 15-6-2014 22:45:22 United States #
Sauvegarde Externe

Voir mon superbe post : <a href="http://jesusreyna.org">Sauvegarde Backup</a><br/>

Voyance directement 16-6-2014 01:24:23 United States #
Voyance directement

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

voyance : 16-6-2014 06:10:00 United States #
voyance :

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

voyance 16-6-2014 17:38:09 United States #
voyance

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

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

Simply because I initially wrote in excess of MBT footwear at <strong><a href="incaltaminte-mopiel.ro/.../category&path=18_46"; 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 19-6-2014 00:18:22 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 14-7-2014 15:10:21 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 9-4-2015 09:39:21 United States #
Jarred

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 29-4-2015 04:30:10 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 3-5-2015 23:50:56 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 http://www.creatori.net/optimizare-texte

Hidroplasto 4-5-2015 17:51:53 United States #
Hidroplasto

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

Hidroplasto 4-5-2015 20:04:22 United States #
Hidroplasto

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 8-5-2015 16:44:07 #
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 15-5-2015 18:35:21 United States #
��C

Top site, a bientot sur la toile

Evonne Figone 4-6-2015 09:34:20 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 13:35:25 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 9-6-2015 12:30:52 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 9-6-2015 17:50:48 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 cotakpachnie.com.pl/.../

bandar bola 20-6-2015 23:16:08 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 22-6-2015 05:37:20 United States #
tom

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 10-7-2015 03:58:08 United States #
Marco

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 16-7-2015 11:30:11 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 16-7-2015 12:37:06 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 16-7-2015 15:20:40 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 16-7-2015 16:12:59 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 16-7-2015 21:05:51 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 18-7-2015 15:02:21 United States #
Jesusa Pernice

Ex-NFL Player Mistress Murders Wife ... Cops (Update): http://adf.ly/1KzuSd

Marco 22-7-2015 02:38:15 United States #
Marco

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 23-7-2015 12:26:14 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 26-7-2015 07:02:24 United States #
click through the following document

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

limited edition agua bendita 29-7-2015 03:23:55 United States #
limited edition agua bendita

Lucien Webbink 29-7-2015 23:44:57 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 30-7-2015 23:06:08 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 6-8-2015 10:55:58 United States #
Rory Leatherman

Cary Mcsweeny 6-8-2015 14:05:25 United States #
Cary Mcsweeny

agua bendita bikini 6-8-2015 14:25:35 United States #
agua bendita bikini