This framework for a Visual Studio single file generator will be accompanied by an article (yet to be written). The intent is to provide a simple way to write a single file generator.
The basis for this framework can be veiwed at VSIX Deployable Single File Generator Sample
This framework and steps to use it are designed ONLY for Visual Studio 2010 (because that is what I have)
- Ensure that the SDK for Visual Studio 2010 is installed
- Download the solution from github
- Open the downloaded solution
- Create your transformation provider assembly ...
Add->New project->Visual C#->Windows->Class Library
- Reference the
SingleFileGeneratorInterface
assembly - Create your transformation provider class ...
Add->Class ...
and inherit fromBadCompany.SingleFileGeneratorInterface.IProvider
and implement this interface - Sign this assembly with a strong name key
- Create your package assembly ...
Add->New project->Other Project Types->Extensibility->Visual Studio Package
(Navigate through the wizard) - Reference
SimpleFileGenerator
,SingleFileGeneratorInterface
and your transformation provider assembly - Copy
C#\SimpleFileGenerator\CodeGeneratorRegistrationAttribute.cs
from the code to your package assembly project (it's license makes me unwilling to supply it directly) - Create your transformation provider bridge class (NOTE: the name of this class is the name of your custom tool) ...
Add->Class ...
and replace it with the following body (adjusted for your namespace/class name/etc)
namespace XxxMyPackage
{
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.Demo.SimpleFileGenerator;
using BadCompany.SingleFileGenerator;
[ComVisible(true)]
[Guid(GuidList.guidMySingeFileGeneratorPkgString)]
[ProvideObject(typeof(XxxMyCustomTool))]
[CodeGeneratorRegistration(typeof(XxxMyCustomTool), "XxxMyCustomTool", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", GeneratesDesignTimeSource = true)]
public class XxxMyCustomTool : VsSingleFileGenerator<XxxMyProvider>
{
}
}
- Compile
- Debug your package assembly (your transformation provider may still throw new NotImplementedException() if you have not done anything more that implement the interface in the steps above)
- I am NOT an "Extensibility" expert - probably not even a novice
- The GUID
"{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}"
means that your SFG is suitable for a C# project- You can locate other GUIDs in the
Microsoft Visual Studio 10.0/Common7/IDE/PublicAssemblies/VSLangProj80.dll
assembly - I did add the VisualBasic GUID, but it did not appear to run correctly
- You can locate other GUIDs in the
- You can quite easily move all the code into the package assembly, I prefer to split it up so that I can unit test the transformation provider
- When implementing
IGeneratorProvider.WriteOutput
, do not use theinputFilePath
argument to read the content, but rather useinputFileContent
, this allows for easier unit testing - You might strongly consider following the steps at VSIX Deployable Single File Generator Sample to make your SFG available to Express editions of Visual Studio