Archives / 2009 / December
  • Migrating from VS 2005 to VS 2008

    I recently helped migrate a ton of code from Visual Studio 2005 to 2008, and .NET 2.0 to 3.5. Most of it went very smoothly; it touches every .sln, .csproj, and .Designer.cs file, and puts a bunch of junk in Web.Configs, but rarely encountered errors. One thing I didn't expect was that even for a project running in VS 2008 but targeting .NET Framework 2.0, it will still use the v3.5 C# compiler. As such, it does behave a bit differently than the 2.0 compiler, even when targeting the 2.0 Framework.

    One piece of code used an internal custom EventArgs class, that was consumed via a public delegate. This code compiled fine using the 2.0 C# compiler, but the 3.5 compiler threw this error:

    error CS0059: Inconsistent accessibility: parameter type 'MyApp.Namespace.MyEventArgs' is less accessible than delegate 'MyApp.Namespace.MyEventHandler'

    It's a goofy situation, the error makes perfect sense, and it was easy to correct (I made both internal), but I expected VS 2008 would use the compiler to match whatever the target .NET Framework version was. I wouldn't have expected any compilation errors it didn't have before conversion, not until I changed the targeted Framework version.

    Another funny error happened around code analysis. Code analysis ran fine in VS 2005, but in VS 2008, it threw this error (compilation error, not a code analysis warning):

    Running Code Analysis...
    C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe /outputCulture:1033 /out:"bin\Debug\MyApp.Namespace.MyProject.dll.CodeAnalysisLog.xml" /file:"bin\Debug\MyApp.Namespace.MyProject.dll" /directory:"C:\MyStuff\MyApp.Namespace.MyProject\bin\Debug" /directory:"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" /directory:"..\..\..\Lib" /rule:"C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules" /ruleid:-Microsoft.Design#CA1012 /ruleid:-Microsoft.Design#CA2210 ... /searchgac /ignoreinvalidtargets /forceoutput /successfile /ignoregeneratedcode /saveMessagesToReport:Active /targetframeworkversion:v2.0 /timeout:120 MSBUILD : error : Invalid settings passed to CodeAnalysis task. See output window for details.
    Code Analysis Complete -- 1 error(s), 0 warning(s)
    Done building project "MyApp.Namespace.MyProject.csproj" -- FAILED.

    I especially like the "See output window for details," which 1. screams of a Visual Studio hack as it is, and 2. doesn't actually give me any more details in this particular case, though Google tells me that other people do get more information in the output window.

    I noticed Debug and Release modes both had code analysis enabled (I think switching Framework versions swapped them on me and I accidentally enabled it in Release mode), and Release mode wasn't erroring out but Debug was. I looked at the difference in the csproj file, and in the FxCopCmd.exe calls, and the key seemed to be the /ruleid parameters (bolded), of which there were a ton in Debug but not Release. Presumably this is because I disabled some of the rules in the project properties, so I tried enabling them all. The number of /ruleid params went down, but it still gave the same error. The Code Analysis tab in project properties looked the same between Debug and Release.

    Finally I unloaded the project, edited the csproj file (I'm glad I found out how to do this within VS, instead of exiting VS and editing it in Notepad), and removed this line, which was present in the Debug PropertyGroup element but not the Release one:


    Code analysis then ran successfully. I imagine this solution isn't ideal for everyone, if you want to enable/disable particular rules, and it's not ideal for us long-term, but it did allow us to keep code analysis enabled without the build failing.


  • Windows 7 rocks!

    I bought my current PC almost three years ago. I've had my own PC for 15 years or so, and, aside from my first desktop and a laptop I only use when traveling, that was the only time I've bought a whole PC, rather than buying parts and assembling my own (a Frankenputer as former coworkers affectionately referred to them). Like many of my colleagues who work in Microsoft technologies, I looked into buying a Dell, and they had a fine deal, and more importantly, they had finally started selling AMD processors, which I can proudly say without qualification is the only CPU in any computer I've owned. I configured one with a dual core, 64-bit processor, and all sorts of new technologies I'd never heard of but were (and appear to still be) the latest and the greatest. ("What's SATA? We use PCI for video again?" I asked myself.)

    Windows Vista had RTM'd and was weeks from retail availability, and my PC included a deal to upgrade once Microsoft let Dell send upgrade discs. My PC had a rather small (160 GB, I think) hard drive, which I intended to replace with a 500 GB or so once Vista came out, installing it there fresh instead of trying to upgrade Windows--Windows upgrades have never worked so well for me, whereas fresh installs are fine. Then I heard all the complaining about Vista, and decided to hold off. I ran low on space before Vista SP1 came out, so got that second hard drive anyway and kept my photos there. From then on, Windows XP Professional worked "well enough" so I stuck with it.

    Things got bad a couple months before Windows 7 came out. First, Norton AntiVirus misbehaved. To be fair, the program was about 6-7 years old; I kept it around because it seemed to work well enough, I got it free as a student, and virus definition upgrades were free. Then I noticed the dates on the definitions went from a few days ago, to the middle of 1999. It still changed every week, and still found upgrades, so I'm guessing it was just a bug in how it displayed the definitions date, but still made me nervous, as did the prospect of uninstalling old and installing new virus scanners.

    Roxio was the next to act up. After Microsoft paved the way with Windows Update, suddenly every software manufacturer was convinced their product was just as important to check at least every week for updates, and the updates, just as urgent. Eventually I got Apple to quit bugging me to install Bonjour and Safari, but I couldn't get Roxio (or, perhaps more accurately, InstallShield Update Manager which came with Roxio) to quit prompting me to check for updates on the 0 products I had told it to check. I googled and finally found a tool I could use to uninstall that piece of it, without uninstalling Roxio, on InstallShield's support site.

    That was a mistake. It stopped prompting me, but added about 3 minutes from when Windows comes up after I start my PC, until my computer was usable, and in the meantime, Norton was disabled, Windows Firewall was disabled, and programs wouldn't start. Add to this a nagging problem where my SD/CompactFlash card reader thinks it's USB 1.x intermittently, and the ugly way Windows Search was grafted onto Windows XP, and the fact that XP (and earlier versions of Windows--not sure about 7 yet) just slows down after a couple years, and I knew it was time to upgrade once Windows 7 came out.

    The more I learned about Windows 7 (and, to be fair, much of it was new in Vista and largely unchanged in 7, but I'd barely ever used Vista), the more I liked it. The way search worked much faster, more efficiently, and was integrated into everything, even the Start Menu (no more reorganizing each program's 20 or so icons so I could find the ones I actually wanted! no more sorting alphabetically every time I install a new program!)... An overhauled Windows Explorer including a new Libraries feature (not in Vista) that didn't force you to keep everything in your profile for Windows to like it... and finally getting to install 4 GB of memory and take advantage of my 64-bit processor!

    After Microsoft decided one day the long-activated Windows XP installation on my laptop was no longer valid, with no explanation why, I wasn't going to chance them deciding the same thing on my main PC, so I broke down and got the full version of Windows 7. I opted for Home Premium after finding little difference between Home Premium and Professional that I cared about, since Home Premium should be able to run IIS, and if it can't, Visual Studio 2008's web server should be enough for what I need on this PC. I installed it not quite a month ago, replacing NAV and Ad-Aware with the new free and highly-rated Microsoft Security Essentials, and Roxio with--well, either what's built into Windows 7 or my favorite CD ripper Easy CD-DA Extractor, and it's great. I can work the way I want to, customize things as much as I need (you're close, iPhone, but not quite there), and boy is Aero pretty. I'm a sucker for eye candy (I do have an iPhone).

    The search works great. I was leery about using Windows Search (installed against your will by Office 2007) or Google Desktop Search (must be unchecked in order to not install with every Adobe program and tons of others) add-ons for Windows XP; that sort of thing just seems like too core a functionality to get some freebie add-on to handle. Windows XP's built-in search might suck, but it usually found what I wanted, and didn't take too long. Sure enough, Windows 7 search works instantly, and if you copy over a ton of files it hasn't indexed, as I did when I wiped my hard drive to install 7 then copied back from my backup, it might not find everything right away, but it will after it spends a few minutes indexing them. And, as advertised, it doesn't slow me down while I'm using the PC; I haven't heard my hard drive crank once while I've been writing this long post. By default, it only indexes in your Libraries, and MS suggests anything you want indexed, you put in a Library. That put me off at first--what if I need to search for a system file or something?--but really, the vast majority of stuff I search for slots fine in either the Documents, Music, or Pictures Libraries. Moving from XP to 7 takes some adjustment, but I gave it a chance, and I'm quite happy with it. And if I do ever need to do a search for a certain DLL, it's easy enough to add folders to the list of what's indexed. I don't even have to dig into Administrative Tools and various Control Panel applets and System Tools folders, wondering where Microsoft has hidden that options screen in this version, thanks to the Start Menu search feature. I just click the Windows key, type "index", and it's the first option:


    Just like searching on the web, the content is what matters; its physical location is now much less important. You just type in a word or two and it figures out what you want, no matter where it is.

    Another great and long-overdue improvement is the Windows Explorer dialogs for long-running file operations--deleting, copying, moving. It gives you more of the path, and best of all, an accurate estimate of how long it will take, and the rate at which it's copying files! No more operations where it takes 45 seconds for the first part and 23987105 minutes for the last part.

    The most annoying thing I've found so far is based on principle, and not any difference I've observed. Occasionally, programs crash. Two that I use often, Mozilla Firefox and IrfanView, have each crashed once. (Amusingly, both when they tried to start up the Apple QuickTime plug-in; I have a few things to say about my iTunes migration experience, but that'll have to wait for another post.) But once is all it takes in Windows 7, before Program Compatibility Assistant (PCA) kicks in and applies some sort of mysterious sanctions to the offender.


    Obviously I was curious about what those "settings" it applied were, and how to grant amnesty for first-time offenses. That link has a help article with those exact questions. And the answer? "It depends," and "go to TechNet and teach yourself about group policy," respectively. (In their words, "Adjustments to program compatibility features can be made by using Group Policy. For advanced information on how to use Group Policy, go to the Microsoft website for IT professionals.") Seriously? A little more googling and I found out that you can dig into it, or disable PCA altogether, using Group Policy Editor, which... doesn't come with Home Premium. So it sounds like my only choice is manually editing the registry. I can't even find out what PCA changed about how those programs run; a few articles allude to ominous performance degradations in order to ensure stability. Windows 7 addresses so many things that bugged me about XP and earlier versions; it's a shame they dropped the ball on this one. To be fair, it seems that this is how Vista functioned, and Windows 7 didn't make it worse, but didn't improve it, either.

    But, to summarize, I'm thrilled with Windows 7, and with 64-bit computing, though I'm a little surprised more programs aren't 64-bit (Firefox and Flash Player, I'm looking at you). Oh well--we had the same problem switching from 16-bit to 32-bit, but I'm glad enough software and hardware is there, that I can upgrade and work just fine until the rest of it makes it.


  • TFS deleted files still show up in Source Control Explorer

    One problem I've had in Team Foundation Server since Visual Studio 2005 and still in VS 2008 is when items are deleted by someone else, they still show up in Source Control Explorer, with a gray folder with a red X icon, even with "Show deleted items in the Source Control Explorer" unchecked in VS's Options dialog. Sometimes getting latest of the parent clears things up, but other times it doesn't, even with Get Specific Version with both Overwrite boxes checked to force a get. In this case, the only option I've found is to delete my workspace and recreate it, which means checking in everything beforehand, and getting latest of my working branches afterwards. It's a pain, but as specified here and approved by a Microsoft employee, that may be your only option until it's fixed--fingers crossed for VS 2010. (We won't get into the other things for which my fingers have been crossed since I first used TFS in 2005, things that VSS did just fine, such as rollback, check in changes and keep checked out, and search.)