Rants Tagged with “Visual Studio”

1  2  3  4  5  >  >>  (Total Pages: 5/Total Results: 46)

When is a ASP.NET Project Not an MVC Project?

Silverlight Logo

I am working on a hybrid ASP.NET MVC and MVC Dynamic Data project. To work on it I started with the MVC Dynamic Data project assuming this would be a Dynamic Data Project and an MVC project. As Scott Hanselman recently posted, you can mix and match pretty easily so the code was working but I was missing an important piece of functionality in Visual Studio:

My project wasn't being showing these items (or other menu options specific to MVC apps). I suspected it was some magic in the project file so I opened it up in my favorite editor:

<Project ToolsVersion="3.5" 
         DefaultTargets="Build" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">
      Debug
    </Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{F7526D86-12B4-434F-8355-20592CFC4937}</ProjectGuid>
    <ProjectTypeGuids>
      {603c0e0b-db56-11dc-be95-000d561079b0};...
    </ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Foo.Web</RootNamespace>
    <AssemblyName>Foo.Web</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  </PropertyGroup>

The missing bit was a special ProjectTypeGuid: {603c0e0b-db56-11dc-be95-000d561079b0}. You need to add this to the existing ASP.NET project's ProjectTypeGuid list in the project file and magically the project item types appear.

HTH

Congratulations Sara Ford!

Silverlight Logo

After 382 Visual Studio Tips and a book, Sara is retiring the series.  Those tips have been hitting my RSS Feed for a long time now. They've been helpful to me and my students. I really appreciate all her hard work helping us in the community.

Sara Ford's Blog

Silverlight Logo

I am surprised when I talk to developers these days and they don't know who Sara Ford is.  She's responsible for CodePlex and many open source initiatives at Microsoft. In addition, her blog is an excellent source of information on Visual Studio tricks and features that most of us have never noticed.  It is well worth a read. Just announced today, her blog is now available in Russian and Spanish so if English isn't your native tongue, you're in luck there too.

Wonder how I get someone to translate my blog into other languages ;)

The Document Outline in Visual Studio 2008

Silverlight Logo

Something I never noticed before is the Document Outline window in Visual Studio (2008?).  When editing large XAML files this is particularly useful to help navigate the tree of elements.

If you've never noticed it like me, you can make it show up by using the menu's when a XAML file is open:  View->Other Windows->Document Outline. Alternatively, the default key command is Ctrl-Alt-T.

This is *not* a Silverlight specific feature.  It works with WPF as well (but not ASP.NET pages). Nice....

 

 

 

 

Regionate Can Cause LINQ to SQL to Fail

I've been using a LINQ for SQL model for a project for a few months now.  The project has been compiling fine forever now.  Suddenly it was failing to build the .dbml file for no apparent reason.  A quick search for the problem turned up an issue with Regionate and LINQ for SQL.  Uninstalled Regionate and its back to compiling. 

I like the tool but until they fix the issue, i'll have to live without it for a while.

Visual Studio 2008 PowerCommands

Not sure when these were released but someone on Witty mentioned this release. Its a cool number of little features for Visual Studio:

  • Collapse Projects
  • Copy Class
  • Paste Class
  • Copy References
  • Paste References
  • Copy As Project Reference
  • Edit Project File
  • Open Containing Folder
  • Open Command Prompt
  • Unload Projects
  • Reload Projects
  • Remove and Sort Usings
  • Extract Constant
  • Clear Recent File List
  • Clear Recent Project List
  • Transform Templates
  • Close All

Go grab them now.  You know you want them...

Getting Silverlight XAML Intellisense in VS2008

bad intellisense

I've gotten the question a number of times about problems getting intellisense with Visual Studio 2008. If your XAML looks like this in Visual Studio 2008 then I can help you:

 

 

 

 

right click menu

The problem stems from the fact that VS2008 wants to open .xaml files in the WPF Designer. Instead you can get intellisense and a better-faster experience if you open your Silverlight XAML files in the XML Editor.  Most people assume that the intellisense is the lack of the Silverlight XSD file in the installation, but in fact VS2008 includes the Silverlight XSD document (but is unaptly named WPFE.XSD). To solve the problem of opening the file in th wrong editor, right click your XAML file in the solution explorer and pick "Open With..." (see right).

 

 

 

Open With... Dialog

Once that dialog is open, you can pick the "XML Editor" and it will open the file with full intellisense.  I usually click the "Set Default" button as well to always open XAML files (for both WPF and Silverlight) in the XML editor.  I use Blend to edit these files and I am not a big fan of the built-in editor (as it seems to be designed mostly for Windows Forms developers to create simple experiences.  You can see the "Open With..." dialog below:

Let me know if you have any questions!

Visual Studio 2008 for .NET 2.0 Development - An Interesting Quirk

I've been converting some projects to Visual Studio 2008 (but not .NET 3.5) to see if I like the new IDE better than 2005.  So far I can't tell a big difference (though the improved Script debugging is nice).  I did find out something interesting...

I use the 'prop' snippet (if you don't know what this is, in 2005 or 2008 type 'prop' {no quotes} and hit tab twice) to add simple properties.  In 2005 it stubs out the field and the property.  But in 2008 it stubs out an implicit property.

If you are not familiar, implicit properties look like this:

class Foo
{
  public int MyProperty { get; set; }
}

The compiler creates a field for you at compile time automatically.  Cool, right?  Well I was writing some new code and hit the 'prop' snippet in 2008 and got the new syntax but I was perplexed.  Doesn't 2008 know I am running against NET 2.0?  This certainly won't work, right?

Nope...it works.  Why? Because you are targeting the 2.0 Framework but using the C# 3.0 compiler.  Consider the following code:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8
{
  class Program
  {
    static void Main(string[] args)
    {
      Foo foo = new Foo() { MyProperty = 15 };
      Console.WriteLine(foo.ToString());

      string[] names = new string[] { "Shawn", "Bob", "Alice" };
      Console.WriteLine(names);

      // CAN"T USE LINQ as System.Core and 
      // System.Linq require .NET 3.5!
      
      //var coll = from n in names
      //           select n;
      //Console.WriteLine(coll);

      Console.ReadLine();
      
    }
  }

  class Foo
  {
    public int MyProperty { get; set; }

    public override string ToString()
    {
      return MyProperty.ToString();
    }
  }
}

The simple property defined in the Foo class works because the C# compiler is creating the correct code for the .NET 2.0 Framework to use.  Notice that I tried to do some LINQ code but that requires System.Core and System.Linq (both of which are only available in the .NET 3.5 Framework. As long as you are using C# 3.0 features that don't require .NET 3.0 or 3.5 assemblies, the compiler features still work.  If you were paying attention, I used the object initializer syntax too. 

The thing to think about is that if you are using VS 2008, you're using the new compilers (VB and C#) but targetting the right version of the Framework.  I don't know this for sure, but I suspect that targetting .NET 2.0 is actually targetting .NET 2.0 SP1.  I'll know soon when I try to deploy my first site to my 2.0 host.

This may be a boon for people stuck on the .NET 2.0 framework for deployment but want to use some (not all) of the new C# 3.0 features.  I haven't tried this in VB...i'll leave that to my VB MVP's!

Installing Visual Studio 2008 over Beta 2

Scott Guthrie has a new blog post instructing people how to cleanly uninstall all the Beta 2 bits on a machine before installing the RTM of Visual Studio.  This is a great list but if you're an early adopter like I am beware. 

If Beta 2 was your first test build of Visual Studio 2008 (Orcas), you should be good.  If you installed Beta 1 or any of the CTP's, I have found that paving a machine is the only way of really cleaning up some of the crud left by the earlier betas. Beta 2 was very good about cleaning up in an uninstall scenario, but Beta 1 was not (as well as not behaving great side-by-side with VS 2005).  It was a beta afterall so no harm no foul.  But if you have installed early bits, i'd suggest starting with a clean machine.

On the other hand, if all you have is VS 2005 on your machine, the RTM (like Beta 2) works great side-by-side for those of us who need to keep 2005 sln file compatiility.

Visual Studio 2008 Release and Silverlight Development

Now that Visual Studio 2008 is released it would be nice to do some Silverlight development on it (instead of the Beta).  Good and bad news:

Silverlight 1.0:

          http://wildermuth.com/.../Installing_Silverlight_1_0_Templates_on_Visual_Studio_2008...

Silverlight 1.1: