Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single file generator example

I want to implement a single file generator (aka custom tool) in Visual Studio.

Over the last couple of days, I have checked out loads of examples. So far, I've managed to have no success in getting these to run. Tonight I found what looks to be the best example here... https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/Single_File_Generator

the readme.md file includes a set of steps to follow to get it to work. However, as per every other example that I have tried so far, the result is the same.

Cannot find custom tool 'XmlClassGenerator' on this system.

I've tried examples of stack overflow, code project, various blogs, and now github. All of which end in the same result. I've pored over the registry looking for my class guids, looking to see if everything is installed as per the instructions from all the examples that I've followed, including the MSDN website.

Every time, I end in the same frustration. Can anyone help to get this example working?

Here's the steps that I followed

  1. downloaded VSSDK-Extensibility-Samples-master.zip.
  2. extracted zip.
  3. ran Visual Studio 2015 in administrator mode.
  4. opened VSSDK-Extensibility-Samples-master\Single_File_Generator\C#\GeneratorSample.sln
  5. performed nuget restore, and update
  6. compiled solution
  7. followed the steps from readme.md

Here's the steps from the readme.md file that I followed

  1. To run the sample, hit F5 or choose the Debug > Start Debugging menu command. A new experimental instance of Visual Studio will launch.
  2. Once loaded, create a new project. Ex:_ WpfApplication_
  3. Add a new XML file to the project. File > Add > New File
  4. Populate the new XML file with content using the schema from XmlClassGeneratorSchema.xsd. For a working example, Copy/Paste the code from Example.XmlFile.xml into your new XML file.
  5. Open the Properties window for the xml file and set CustomTool to XmlClassGenerator.
  6. Save the XML file. This triggers the single file generator to run and generate a new C# file.
  7. The new C# file is added to the project with the same name as the XML file. This new file appears in Solution Explorer as a dependent of the original XML file node.
  8. Any errors will be reported in the Error List toolwindow.

I've also built a brand new Virtual machine with windows 10 pro N installed, and visual studio 2015 community edition, so I have new tried this on two seperate machines with the same result. For those interested in step 4, I used the content of the Example.XmlFile.xml.

Further update.

In addition, I've performed a nuget up date on the solution as there were a couple of updates available.

Next, I have added set the "Register for COM Interop" flag in the solution build properties.

Executed C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /tlb Microsoft.VisualStudio.Shell.Interop.dll

Still have the same issue at this point. But at least everything is up to date and building.

Next I've performed a search on the registry to see that the guid is correctly registered. And I've manually added an item into the generators registry key under HKey_Local_Machine\Software\Wow6432node\Microsoft\VisualStudio\14.0\Generators{FAE04EC1...}\XmlClassGenerator This has values for CLSID and GeneratesDesignTimeSource

At this point, I'm still getting the same error "Cannot find custom tool 'XmlClassGenerator' on this system.

One last thing that I'm trying is putting the registry stuff under

HKEY_Current_User\Software\microsoft\visualstudio\14.0_config\Generators{FAE0...}\XmlClassGenerator

And again, this has no effect.

Final thing that I had to attempt. I've just added the GeneratorSample.dll to the GAC and again no effect.

like image 443
Colin Dawson Avatar asked Oct 26 '25 12:10

Colin Dawson


1 Answers

After much looking around and struggling. I decided to follow this guide to the letter, and it worked.

http://www.codeproject.com/Tips/1023337/Custom-Tool-Single-File-Generator-for-Visual-Studi

The things that I've done different from the above is to put the dll in c:\program files\Tool. In addition, I've also put the registry entry only in HKey_Current_User....\14.0_Config\Generators

like image 69
Colin Dawson Avatar answered Oct 28 '25 03:10

Colin Dawson