Visual Studio 2010: ApplicationIcon

by Aaron 30. June 2011 02:45

I recently had need to associate a different icon to my C# project based on the selected configuration (i.e. Debug, Release, SomeCustomConfigurationYouCreatedToBeClever).

I did the standard thing of right-click on the project in the Solution Explorer, select Unload Project. Then I again, right-click on the project and choose Edit MyFancyProject.csproj. ApplicationIcon was easy to find.

I tried several ways of setting the icon. I tried a handful of ApplicationIcon nodes with Condition attribute set to " '$(Configuration)' == 'SomeCustomConfigurationYouCreatedToBeClever' ".  I added a line for each of the different configurations.

I saved and reloaded the project into Visual Studio.  The icon it showed wasn't the icon for the selected configuration.  I checked the syntax in the CSPROJ file with no luck.  I changed it to a Choose element with multiple conditions to add a new PropertyGroup with the appropriate icon.  Again, Visual Studio showed me the wrong icon.

Finally, I added the ApplicationIcon element to each of the $(Configuration)|$(Platform).  Still, didn't work!

I decided to just try compiling the application to see what icon was embedded and displayed for the executable after a build.  The icon was right!

The moral of this story is that Visual Studio doesn't process the conditions set in the CSPROJ file, but will process it during the build.

Tags: , , , ,

Visual Studio 2010: Add New Item to Project Issue

by Aaron 23. January 2011 04:56

A couple of weeks ago, we got an email from one of the developers on our project who happened to be working off-site for the day.  It said:

Are any of you able to add a class to Fake.Project.Name?  The dialog
has no installed templates listed when I try.

Of course I thought it was user error until I tried it myself.  This is what I saw:

Add new item - empty template list

Notice that it's an empty list.  I tried another project and got a dialog that actually had what I was looking for:

Add new item - correct list

I did some work with Great Migrations, so I learned a bit about what makes up a project file to tell Visual Studio what is the project type, the language, etc.  It's all very Microsoft-oriented GUID-oriented, much like SharePoint and TFS.  So I suspected that the project file had gotten corrupted somehow with a bad GUID or a GUID that was removed.

The odd thing is that the projects were originally created in Visual Studio 2008 using C# for .NET 3.5.  They were upgraded for Visual Studio 2010 using the upgrade wizard.  Nothing about the project was hand-edited.  Regardless, I did a comparison of the project files to see what the differences were, paying close attention to anything that defines the type of project and language.  This is the first thing that caught my eye:

It's a minor thing, but the offending project (bottom pane) has a GUID in the ProjectTypeGuids node in lowercase, while the working project has it in uppercase.  Starting with a simple solution, I changed the GUID in question to be all uppercase.  Success!

While I can't be certain, it appears that it's doing a case-sensitive string lookup on the ProjectTypeGuids, or at least that one.

If you encounter an issue like this, checking and comparing the GUIDs in your project file is quick and easy.

Tags: , , , , , , ,