Dan Rigsby - Coding Up Style

.Net, C#, & Wcf Development

Archive for the 'Visual Studio' Category


New Webcast: Creating Snippets in Visual Studio

Posted by Dan Rigsby on 9th June 2008

I have a new 4 min 47 sec training webcast out over creating code snippets in Visual Studio 2005 and 2008.  The video is available through JupiterMedia and can be viewed at http://www.internet.com/video/. Just look for the "Developer Video" titled "Creating Snippets in Visual Studio".  Direct link is:

http://www.internet.com/video/?bcpid=1431564240&bclid=1433966034&bctid=1589625246

Posted in Visual Studio, Webcast | 2 Comments »

New Webcast: CSS Support in Visual Studio 2008

Posted by Dan Rigsby on 22nd April 2008

I have a new 7 min 50 sec training webcast out over the CSS Support in Visual Studio 2008.  The video is available through JupiterMedia and can be viewed at http://www.internet.com/video/. Just look for the "Developer Video" titled "CSS in Visual Studio 2008".  Direct links are:

http://www.internet.com/video/?bcpid=1431564240&bclid=1433966034&bctid=1499645387
http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1499645387

Posted in Visual Studio, Webcast | 1 Comment »

Visual Studio 2008 & ClickOnce Warning

Posted by Dan Rigsby on 16th April 2008

Visual Studio 2008 added a new feature to easily embed a manifest.  This is available right from the project properties page. It can be used to embed UAC data for Vista or other things.

ClickOnceManifest

By default each project is selected to use the embedded manifest.  This doesn’t sound too harmful, right?

Well, ClickOnce and Registration-Free COM applications require an external manifest.  So, if you use ClickOnce, it will try to create it own external application manifest which could cause a conflict with the embedded one. Here is the error you might get when you try to install the ClickOnce application:

ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * Activation of \\MyShare\MyApplication.application resulted in exception. Following failure messages were detected:
        + Reference in the manifest does not match the identity of the downloaded assembly MyApplication.exe.

This error seems a bit cryptic at first.  Especially if you don’t know that Visual Studio is embedding a manifest for. Fortunately, this error is easy to get around.  You simple just set this option to “Create application without a manifest”.  Or manually add “<NoWin32Manifest>true</NoWin32Manifest> ” to your project file like so:

<PropertyGroup>
    <Configuration Condition=” ‘$(Configuration)’ == ” “>Debug</Configuration>
    <Platform Condition=” ‘$(Platform)’ == ” “>AnyCPU</Platform>
    <ProductVersion>9.0.21022</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyApplication</RootNamespace>
    <AssemblyName>MyApplication</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <NoWin32Manifest>true</NoWin32Manifest>
  </PropertyGroup>
 
 

Posted in ClickOnce, Visual Studio | No Comments »

How to open a project file in Visual Studio 2008 for editing

Posted by Dan Rigsby on 11th April 2008

How many times have you opened up a .csproj file and wanted to edit the xml, but it opened up the actual project in Visual Studio instead?  Your only real options have been:

  1. Open the project file in a different text editor
  2. Give the project file a new extensions, then open it in Visual Studio
  3. Use some custom visual studio extension or write your own

Microsoft released a set of PowerCommands for Visual Studio 2008 which provides this functionally.  With this you can just right click on the project and select “Edit Project File”:

PowerCommands1

This will open the project file in the visual studio xml editor. This makes it so much better than an external editor because it allows for intellisense through the xsd schema (http://schemas.microsoft.com/developer/msbuild/2003)!

PowerCommands2

Notice though that while you are editing the project, it becomes unavailable in the Solution Explorer.  This is a side affect, because if you are editing the file, Visual Studio can’t yet know what it is going.  So, when you are done editing the file, you have to right click on the project in Solution Explorer and reload, or close the xml editor and reload the project. It would have been nice if it could have just detected when the project file was changed and then asked the user if he/she wanted to reload the project now.  This would be consistent with what you see if you edit the project file in an external editor.

The PowerCommands collection contains a number of other enhancements which you can see on the project website.  Some of my favorites are:

  • Copy and Paste References: Allows you to copy to the clipboard a project reference or set of references and paste them into another project
  • Copy and Paste Class: Allows you to copy a class to the clipboard which renames the class and to paste it into the project again.
  • Open Containing Folder and Open Command Prompt: Allows you to right click on a file and open the folder or a command prompt at that location
  • Remove and Sort Usings: We got this feature in VS 2008 itself, but you can now run this at the project level to affect all files at once.  Now I wish I could do this with “Format Document” too.
  • Close all documents context menu item:  Allows you to close all open documents.  Sometimes when the designer is getting “funky”, I like to close all files, rebuild, and open it again.  Before I could only “Close all but this” and then close that last document.  With this new command, I can close all of them at once finally!
  • Transform Templates: Allows you run execute a “custom tool” with associated text template items.

I highly recommend that you download these free tools from Microsoft.

Download PowerCommands for Visual Studio 2008 here: http://code.msdn.microsoft.com/PowerCommands

kick it on DotNetKicks.com

Posted in Visual Studio | 1 Comment »

Making "Public" Resources Files: PublicResxFileCodeGenerator

Posted by Dan Rigsby on 27th March 2008

This is probably one of my favorite minor additions to Visual Studio 2008, that you probably haven heard of. 

In previous versions of Visual Studio, if you created strongly typed resources files, all of the properties were “internal”.  If you wanted to expose these properties outside of the assembly, you ran into issues.  You could use a custom tool such as ResxFileCodeGeneratorEx, but that meant that each developer had to have this tool installed and you would manually have to change the custom tool name in the properties window for the resource file:

Properties

You could also make the properties public by running resgen.exe with the /publicClass attribute, but you could not do this directly through Visual Studio.  You would have to create a pre-build event to call resgen like this:

resgen.exe “myfile.rex” /publicClass /str:c#

Now, in Visual Studio 2008 there is another option which should basically make these other options obsolete.  When you are working on the strongly typed resource file, there is a new drop down list at the top of the designer that allows you to change the access modifier to either “internal” or “public”.  This will cause the strongly typed resource “code behind” file to generate properties with the selected access modfier.

Resources

You could also manually set the custom tool to use this new generator in the properties window like so:

Properties2

All of these tools and procedures generate a code behind file (typically named something like resources.designer.cs) that contains the strongly typed resource information.  This file is automatically generated by Visual Studio when the resource file itself is changed.  If you were to go in and change the resource.resx file inside of a text editor, the strongly typed code file would not reflect these changes unless you ran resgen.exe afterwards, or opened the project again in Visual Studio.

Posted in Visual Studio | No Comments »