Using the registry to resolve Visual Studio reference paths.
Note: To skip the long journey of what lead me to figuring this out, click here to go to the howto.
Recently I was asked to look at a fiddler plugin Stan, the founder of this blog, was developing. He gave me a SVN path and asked me to build it and test it.
So I checked out the source code and hit F5. I got a bunch of compiler errors relating to the fact that I didn’t have fiddler installed. I rectified that matter and still got errors. The problem was that the hintpath of fiddler.exe was wrong. On my machine, Fiddler is installed in ‘C:\Program Files\Fiddler2\’, while on Stan’s machine it is installed to ‘C:\Program Files (x86)\Fiddler2′. I consulted the mighty google, which led me to a stackoverflow question. The question pointed out that you can have multiple hintpaths to an assembly. However, I wanted a better solution. What if someone installed Fiddler to a custom location?
I got the idea of using the registry. Fiddler has an installer. Surely the installer records its install location to the registry. It does in ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fiddler2′ (Apparently fiddler is written by a Microsoft Employee). So the question is how to get MSBuild, the tool that visual studio uses to parse project files, to read a value from the registry.
The answer was found in a post on the MSBuild team blog.
How To
Unfortunately, Visual Studio does not allow you to edit hintpaths to referenced assemblies. So you’re going to have to edit your vcproj or vbproj file in notepad or some other text editor. Here are the steps:
- Open the project file in your text editor.
- Look for the <Reference/> element for fiddler.exe. It should look similar to this:
<Reference Include=”Fiddler, Version=2.2.7.5, Culture=neutral, processorArchitecture=MSIL”>
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Fiddler.exe</HintPath>
<Private>False</Private>
</Reference>
- Change the hintpath as follows:
<Reference Include=”Fiddler, Version=2.2.7.5, Culture=neutral, processorArchitecture=MSIL”>
<SpecificVersion>False</SpecificVersion>
<HintPath>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fiddler2@InstallPath)\Fiddler.exe</HintPath>
<Private>False</Private>
</Reference> - Save the file
- Visual studio will detect the file change and ask you to reload the file. If you are using SharpDevelop as you’re IDE, you will have to close and reopen the solution.
Thats all there is to it. Happy coding!
What three things got me here.
Paul Randal wrote a What three events brought you here article on his blog and asked some others in the SQL server community to do the same. I of course was not on that list. However, no one ever invited me to blog about anything before so why should I be shy now.
I have decided to not tell this story in terms of professional accomplishments. For me, my hobbies have always led my career.
Trouble building PHP on Windows
Update: It seems that the facts presented to me in the initial bug report are not correct. I will be revising this article after the facts are settled. For now read the comments.
It all started with a simple bug encountered while trying to get PHP and WCF to play nice. Before you know it I was attempting to compile PHP on windows myself. That’s when I realized how deep the rabbit hole really goes.
These days I program in PHP and .NET for a living. In a past life I was a unix admin for small ISP where most of the internal unix infrastructure was FreeBSD while the managed customers tended to run Redhat. Due to the unique path of my IT career, I usually don’t have a problem compiling open source software primarily targeted for unix on windows. PHP has proven to be a bit of an exception. However, with a little struggle, I got it to compile.
In this case the crux of the struggle was not a lack of documentation, but documentation outdated to the point of being wrong. This is perhaps the one exception to the rule postulated by Dick Brandon, “Documentation is like sex . . . when it is good, it is very, very good; and when it is bad, it is better than nothing.” Thankfully, Pierre of libgd fame pointed me in the right direction on the mailing list. So being a good netizen, I submitted a bug report so that someone with commit access to the php source repo could straighten the mess out. This was the response I received:
We don’t understand the build requirements or system.
You have to ask the Microsoft guys to update that file.
http://no.php.net/manual/en/install.windows.building.php was one of our
best Windows know-how (not-microsoft-employee) guy shot at documenting
the process, but the feedback he got from Microsoft employees was “this
is crap. its all wrong”.Sorry, we simply do not know how to do this.
That was a little disheartening. I asked them to mark the readme file as outdated, and I asked them how to contact Microsoft. This was the response I received:
Updated the file to say its outdated.
As for contacting the Microsoft guys, try surfing around on
http://windows.php.netWe have tried multiple times to get these docs updated, with no luck so
far, and like I said; our last attempt was shot down and they wanted
those docs to be reverted.I’m sorry, you are simply on your own here.
So it seems my only resort is to blog about it and hope someone from Microsoft is in earshot. If you care about PHP on windows, spread the word. Spread this article with twitter, digg, reddit, or just plain old email. If you have the ear of anyone in Microsoft give it a bend. I’ve never attempted blogger activism like this, but I don’t know what else to do. I much prefer to fix problems myself than delegating or inspiring. However, this is one case where I need to “have a little help from my friends.” I don’t even know what Microsoft finds wrong with the proposed updates to the documentation, so submitting updated documentation seems pointless.
Yes your software needs an installer.
Some people have a love-hate releationship with certain pieces of software. Others, a love to hate relationship. My releationship with Eclipse is more of a respect-hate relationship.
Perhaps I make that categorization, because I cannot admit a more purer dichotomy of love-hate, I’ve often described eclipse as being put together by a hippie commune of developers. The features are all nice. However, the complete lack of central planning is very apparent. The fact that there are at least three “Find” dialogs in Eclipse PDT, the Eclipse distribution designed for PHP is testament to this. In the Edit menu their is a find dialog for the current document. In the Search menu there is one dialog for searching for PHP methods, fields, etc. There is also a second that has several tabs for searching for javascript, plain file search, and others.
This is all somewhat acceptable, as Eclipse not only an IDE, but a Framework for making IDEs. There are third party eclipse distributions for editing java, PHP and other languages in eclipse that are more polished. Perhaps its best that the “reference distributions” have the full hodgepodge of features, and third parties take the “less is more” approach.
However, one missing feature I cannot forgive is the lack of an installer. All mature software projects should have proper installers for their platform. For an Apple, this means a .dmg file with a .app bundle built in. For windows this means an MSI, exe, or an exe wrapped around an MSI. For linux this means an rpm and debian package.
That’s not to say I am against the concept of a binary zip or tarball. On the contrary, some people don’t like installers, and they should have the option of just unzipping. Freedom of choice is a good thing. However, I am saying that an installer is one of the necessary choices for all platforms.
As a final aside, I realize that a dmg with a .app bundle is not really an installer on par with an RPM, MSI, or EXE installer. I also realize there are real installers for MacOSX software that a minority of Mac Software uses. So I acknowledge that Mac OSX is an exception to this rule.
Printf() for jquery.
I was preparing for my pre-session talk this past November at LISUG, when I determined that I needed a printf() function for jquery. To be more accurate, more accurately I needed an sprintf() implementation in javascript, and wanted to .
Google lead me to a jquery plugin that has not been updated since 2007. However, sometimes software gets to the point where it really doesn’t need to be maintained, and if it worked for me I was not going to dismiss it as abandoned software.
In the end it did require a small patch to handle %% (really print a percentage sign). Unfortunately, the maintainer has not acted on my patch. However, please apply it if you plan on using it.