Custom Tool in VS2005
-
Friday, July 14, 2006 9:36 AM
Hi, have some troubles creating a "Custom Tool" like "MSDataGenerator":
I read the article found at: http://msdn.microsoft.com/msdnmag/issues/06/02/CuttingEdge/
and some of the linked articles too.
So here are the steps i made in hardly 15 mins:
1. Create new VS2005 C# ClassLibraryProject called "MyGenerator"
2. Add reference to Microsoft.VisualStudio.BaseCodeGeneratorWithSite.dll
3. Implemented: "MyGenerator.cs":
using System;
using System.Runtime.InteropServices;
using Microsoft.CustomTool;
namespace MyGenerator
{
[ComVisible(true)]
[Guid("d1815bb9-ecce-4dbc-9b73-ce4ff234af7d")]
public class MyGenerator : BaseCodeGeneratorWithSite
{
protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("using System;");
sb.AppendLine("namespace Active");
sb.AppendLine("{");
sb.AppendLine(" public class MyGeneratedClass");
sb.AppendLine(" {");
sb.AppendLine(" }");
sb.AppendLine("}");
return System.Text.Encoding.ASCII.GetBytes(sb.ToString());
}
}
}4. Signed it via "Properties"-Page of MyGenerator creating "MyGenerator.snk"
5. Opend the VS2005 Command Line
6. Regasm C:\data\projects\MyGenerator\MyGenerator\Bin\Release\MyGenerator.dll
7. GacUtil /i C:\data\projects\MyGenerator\MyGenerator\Bin\Release\MyGenerator.dll
8. Made the entries in the registry:
created key: HKLM\SOFTWARE\Microsoft\VisualStudio\8.0\Generators\{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}\MyGenerator
created string: "CLSID" = "{d1815bb9-ecce-4dbc-9b73-ce4ff234af7d}"
created dword: "GeneratesDesignTimeSource" = 1
-- rebooted machine
9. Opend other Project, Set Property "Custom Tool" of my file "Test.xml" to "MyGenerator"
Called "Run Custom Tool" -> received error message:
"Custom Tool "MyGenerator" not found.
Is there anything i did not, or did not right? Please Help!
Answers
-
Thursday, July 27, 2006 4:59 PM
I finally figured out what the problem was. There is yet another registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{Custom Tool GUID}
This key defines the assembly. Without it, the custom tool is not found. A better error message seems possible. If the generator is found in:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Generators
and the GUID of the tool is not in the other registry hive, then the error should indicate that.
-
Thursday, August 10, 2006 8:08 PM
There are several settings:
Assembly:MyGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e43b8894831ef994
Class: <namespace>.<classname>
InProcServer32: C:\Windows\system32\mscoree.dll
ThreadingModel: Both
then in key (for c#)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Generators\{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}\MyGenerator
CLSID : REG_SZ : {guid}
GeneratesDesignTimeSource: REG_DWORD : 1
Then make sure you use "MyGenerator" for the custom tool in the project.
All Replies
-
Tuesday, July 18, 2006 10:36 AMup ...
-
Wednesday, July 19, 2006 11:33 AM
I know its not quite nice to up it again, but since i am not the only having problems with that (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=559691&SiteID=1) I wanted to know if someone might create an example from the beginning and tell us what he/she did and if its working?
-
Saturday, July 22, 2006 4:32 AMModerator
My initial guess is that the assembly wasn't registered for COM Interop.
If you register the assembly via regasm.exe without the /codbebase switch, you will need to plant the assembly in either the GAC, or the ..\Common7\IDE\PublicAssemblies or PrivateAssemblies folder.
Note, the Visual Studio SDK has a really nice Single File Generator sample called GeneratorSample. But the registration piece is done through a set of custom attributes, and the registration step is carried out through a custom build task via the Microsoft.VsSDK.targets. If you open the .csproj you'll see where we pull in the .targets file and where we set the RegisterOutputPackage and RegisterWithCodebase, which registered the component via the custom attributes.
Sincerely,
-
Saturday, July 22, 2006 11:48 PM
Why is there any guess work? It is obvious that Visual Studio 2005 needs to perform certain steps to invoke a custom property. Why do we get a plain, waste of time, useless error like "custom tool not found". I am trying to diagnose a custom tool and am ready throw the computer through the wall. If Visual Studio 2005 could at least indicate something like COM object not found, or missing entry in generators registry section, it would go a long way to fixing problems.
I suspect my problem has to do with COM interop, but I will spend the next week tracking it down. I attempted to create a C# object that is visible as a COM object. No matter what I do, it can't be imported:
#import "progid:sharp.object"
It just indicates, invalid progid, even though, the registry has a perfectly nice com object registered.... named sharp.object. Since I can't get a simple C# object to be visible with COM, I don't think I will ever get a custom tool to work. I have tried all the keys, the constantly changing properties (COMVisible set to true), nothing works.
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
-
Tuesday, July 25, 2006 1:37 PMModerator
Hi tkrasinger,
All steps you provided look OK.
Maybe you drop some trash into registry when developing this custom tool?
I usually use following command chain to unregister and register again created custom tool:
RegAsm.exe C:\CodeGeneration\bin\Debug\VisualStudio.CodeGeneration.dll /unregister
GacUtil.exe /u VisualStudio.CodeGeneration
RegAsm.exe C:\CodeGeneration\bin\Debug\VisualStudio.CodeGeneration.dll
GacUtil.exe /i C:\CodeGeneration\bin\Debug\VisualStudio.CodeGeneration.dllAlso sometimes Visual Studio should be refreshed with command devenv /setup
Note: that devenv /setup will reset some of your preferences!!!
-
Thursday, July 27, 2006 4:59 PM
I finally figured out what the problem was. There is yet another registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{Custom Tool GUID}
This key defines the assembly. Without it, the custom tool is not found. A better error message seems possible. If the generator is found in:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Generators
and the GUID of the tool is not in the other registry hive, then the error should indicate that.
-
Monday, August 07, 2006 1:39 PM
Which entries must be created in the ..\8.0\CLSID\{GUID} ?
Maybe i put something wrong or not enough in there.
I created:
Assembly: MyGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e43b8894831ef994
Class: MyGenerator.MyGenerator
But it still doesn't work.
-
Thursday, August 10, 2006 8:08 PM
There are several settings:
Assembly:MyGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e43b8894831ef994
Class: <namespace>.<classname>
InProcServer32: C:\Windows\system32\mscoree.dll
ThreadingModel: Both
then in key (for c#)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Generators\{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}\MyGenerator
CLSID : REG_SZ : {guid}
GeneratesDesignTimeSource: REG_DWORD : 1
Then make sure you use "MyGenerator" for the custom tool in the project.

