Geeks With Blogs

News This is the *old* blog. The new one is at blog.sixeyed.com
Elton Stoneman
This is the *old* blog. The new one is at blog.sixeyed.com

[Source: http://geekswithblogs.net/EltonStoneman]

There are a couple of reasons why you might want PDB files available in the GAC, say if you're running coverage reports over unit tests as part of your CI build, and the assemblies being instrumented all live in the GAC, or if you want to deploy BizTalk PDB files as a troubleshooting aid. Patrick Cauldwell has a PowerShell script to install PDBs to the GAC, which is a good basis for an MSBuild task to do the same.

The principle is straightforward – find the "hidden" GAC directory where it the assembly is deployed and copy the PDB file there. Danger here is that the GAC structure may change, so the task uses AssemblyName.CodeBase which gives you the full path to the physical location, rather than determining it from the current format.

The main work is done here:

string pdbFilename = string.Format("{0}.pdb", Path.GetFileNameWithoutExtension(this.AssemblyPath));

string pdbPath = Path.Combine(Path.GetDirectoryName(this.AssemblyPath), pdbFilename);

//if source PDB is found:

if (File.Exists(pdbPath))

{

//get the strong name info from the assembly:

AssemblyName gacAssemblyName = Assembly.LoadFile(this.AssemblyPath).GetName();

string gacPath = this.GetGacPhysicalLocation(gacAssemblyName);

//if GAC location found:

if (!string.IsNullOrEmpty(gacPath))

{

//copy PDB file:

try

{

File.Copy(pdbPath, Path.Combine(gacPath, pdbFilename));

Log.LogMessage("Added PDB file to GAC: {0}, location: {1}", pdbFilename, gacPath);

}

//log other conditions...

Where AssemblyPath is the path to the un-GACd assembly where the PDB file is expected to be found (e.g. the build output directory):

<Target Name="DeployPdbToGac">

<DeployPdbToGac AssemblyPath="$(BuildOutputDir)\x.y.dll"/>

</Target>

 

Full source code is here: MSBuild Task to Deploy PDB Files to GAC

Posted on Wednesday, September 17, 2008 9:55 PM MSBuild | Back to top


Comments on this post: Installing PDB files to the GAC with MSBuild

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Great task! I was looking for something like this.

I have found a little bug though: You are never setting success = true after successfully copying to the GAC, so the build always fail.


I have another issue, property $(BuildOutputDir) doesn't seem to be defined. The task works for me if I specify the full output path, but I would like to use a property as you are doing. Is there another property that should have the full path?

Thank you very much,
Manuel

Left by Manuel Babuglia on May 29, 2009 5:34 PM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
That's a pretty cool article.The information you have given are really very useful thanks a lot for sharing.Keep blogging.
Left by sozo on Apr 24, 2010 7:28 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Very nice and useful post, thanks.This post is not helpful for newbies also for experts, because it is true everyone is not aware of everything.
Left by content filter256 on Apr 26, 2010 4:19 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Having written articles that require this much work, I commend you for your service to the future bloggers. I’m sure they will appreciate it.Keep it up.
Left by security camera-59 on May 03, 2010 9:24 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Too hard and technical for me to understand... Peace!

Catholic Saints Names List, Patron Saints
Left by Matts Doomsday 2012 on Jul 08, 2010 5:35 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Great post! Thanks for informative listing. Its really helpful for the beginners.Keep blogging.
Left by application blocking491 on Aug 07, 2010 7:29 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
This has been helpful. A quick note to say "thanks." Alexander
Left by flag rental on Sep 14, 2010 4:52 PM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
I have read few of articles here and can say it was really interesting, thanks for sharing this.Hope will post again soon.
Left by get motivated seminars on Oct 09, 2010 8:45 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Thanks a lot for the valuable post about Installing PDB files to the GAC with MSBuild..But it is too hard to understand for me as i am new to this language.
Left by Uffizi tickets reservation on Nov 11, 2010 5:11 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
This is a great task to Installing PDB files to the GAC with MSBuild! I was looking for something like this, as a new learner it’s too hard and technical for me to understand. But this post explains it in such way that is so east to understand for a reader.
Left by leg vein pain on Jan 28, 2011 6:11 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
This has been fruitful for me. I have been working with this type of project. I have gained a lot of newthings from this post. Thanks a lot for sharing such a valuable post with us.
Left by colocation utah on Jan 28, 2011 6:48 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
MSBuild allows you compile C# from the command line..just like NANT. The MSBuild file consists of a Project tag containing Targets, PropertyGroups, and ItemGroups.
Left by submission article on Mar 23, 2011 9:49 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
I want to use PDB files to deploy BizTalk PDB files as a troubleshooting aid. This more appropriate for my business.
Left by online computer science degree on May 13, 2011 6:54 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
This post is well written…thanks for the post!Some great information to be absorbed in this post. Thanks!Keep up the good work.I am interested very much in the subject matter of your blog, it’s my first visit.
Left by driving lessons Birmingham on Jun 17, 2011 3:51 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Thanks for providing the instruction on how to install PDB files to the GAC with MSBuild.
Left by cheap link building on Sep 07, 2011 9:19 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Thanks this post helped massively
Left by Driving lessons Bristol on Sep 18, 2011 5:03 PM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Nice script! It is working well!
Left by Music Lyrics on Dec 22, 2011 5:25 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
I think youve made some really interesting points. Not too many people would basically think about this the way you just did. Im really impressed that theres so significantly about this subject thats been uncovered and you did it so nicely, with so significantly class. Good 1 you, man! Truly terrific stuff right here. bottleless water cooler for offices
Left by buy water dispenser on Dec 23, 2011 11:46 PM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
It's really a very good article,I learn so much thing from it,thanks.You are really a nice person real estate toronto
Left by flor on Dec 27, 2011 7:07 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
I would be very thankful if you continue with quality what you are serving right now with your blog...I really enjoyed it...and i really appreciate to you for this. online english | teaching job in shanghai
Left by lance on Dec 28, 2011 8:34 PM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Great post! Thanks for infor keep blogging.
Left by Driving schools Bristol on Mar 09, 2012 7:00 PM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Great piece very nice article keep them comingdriving lessons Portishead
Left by Driving schools Portishead on Jul 16, 2012 11:33 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
You know Just love NY and this really shows the streetview …the buildings, stairs etc... I say really hot. Alia Bhatt HD Wallpapers
Left by Umar AMin on Sep 17, 2015 6:14 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
The Pakistani fashion industry has many successful fashion designing artists. In the list of best designers both men and women are including. Get latest samsung mobile prices in Pakisnan. Samsung Mobile Prices Specs Pakistan
Left by Yasir Shah on Sep 17, 2015 6:16 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Get all you need for mobile and PC. Mobile SMS Wallpapers Results
Left by Salma Zohaib on Sep 17, 2015 6:18 AM

# re: Installing PDB files to the GAC with MSBuild
Requesting Gravatar...
Nice and Good post, but have you thought about Pain in the neck before? Mahira Khan HD wallpapers
Left by Mahira Khan Biography on Jan 07, 2017 2:51 AM

Your comment:
 (will show your gravatar)


Copyright © Elton Stoneman | Powered by: GeeksWithBlogs.net