Code generator output opens in notepad

  • Thread starter =?iso-8859-1?Q?Lasse=20V=e5gs=e6ther=20Karlsen?=
  • Start date
?

=?iso-8859-1?Q?Lasse=20V=e5gs=e6ther=20Karlsen?=

I found the excellent article by Paulo Reichert at http://blogs.conchango.com/pauloreichert/archive/2005/05/21/1459.aspx,
which shows how to build a code generator for Visual Studio 2005. I followed
this and made a small generator that output a dummy file containing only
this:

namespace TestNamespace { public class TestClass { } }

This works nicely. The namespace and class is available in the project and
I can compile it and check that it's present via Reflector.

However, if in the solution explorer I make it show all the files so I can
see my generated file and double-click on that file, it opens up in Notepad,
whereas the Settings.Designer.cs file opens up inside Visual Studio.

Additionally, if I right-click on Settings.Designer.cs and selects View Code,
the file opens up in VS, but if I do the same on mine I get this error message:

---------------------------
Microsoft Visual Studio
---------------------------
There is no editor available for 'D:\Dev\VS.NET\WindowsApplication113\WindowsApplication113\test.Designer.cs'.

Make sure the application for the file type (.cs) is installed.
---------------------------
OK
---------------------------

I'm not sure what, if anything, to do about this.

Opening up both of these files in a binary editor shows me that the Settings.Designer.cs
file got BOM at the start but mine doesn't, probably because I chose UTF-8
encoding.

If anyone got any advice, please let me know. I can post the project if anyone
wants to look at it, but a "short and complete example" can't be shown in
this post.
 
?

=?iso-8859-1?Q?Lasse=20V=e5gs=e6ther=20Karlsen?=

I found the excellent article by Paulo Reichert at
http://blogs.conchango.com/pauloreichert/archive/2005/05/21/1459.aspx,
which shows how to build a code generator for Visual Studio 2005. I
followed this and made a small generator that output a dummy file
containing only this:

namespace TestNamespace { public class TestClass { } }

This works nicely. The namespace and class is available in the project
and I can compile it and check that it's present via Reflector.

However, if in the solution explorer I make it show all the files so I
can see my generated file and double-click on that file, it opens up
in Notepad, whereas the Settings.Designer.cs file opens up inside
Visual Studio.

Ok, the answer was simple. I used a MemoryStream internally and had used
..GetBuffer() instead of .ToArray(), which meant that the output, and thus
the file, contained 0-bytes at the end, no doubt throwing off Visual Studio.

I fixed that and now it worked nicely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top