问题
Even with F# installed, Visual Studio 2008 (and probably 2010) only provides Add-In project templates for C#, VB.NET and C++.
So, how to create a F# based Add-In?
I have tried to create a F# class library project with a new class implementing IDTExtensibility2, setting the correct references (EnvDTE, Extensibility, ...), copying a few project attributes from the C# Add-In (mainly the command line for debugging), and creating the .AddIn manifest file by hand, but no success. When VS is launched, my Add-In is not listed in the available ones.
What are the missing steps? Some kind of COM registration somewhere?
回答1:
I've not tried this exact scenario, but the general strategy I've had the best luck with is: start with the C# template, rename the .csproj to .fsproj and change the <Import>
s for F# and replace the <Compile>
of C# code with F# code, and go from there.
The templates often have various important logic in them for build/deployment, so start with a working template for C# and tweak it for F#.
回答2:
I finally found what went wrong: I simply forgot to put the .AddIn file in the AddIn directory (the C# wizard is doing this automatically).
So, to create a F# based Add-In for Visual Studio:
- Create a new F# class library project
- Add a few reference assemblies to the project (mainly EnvDTE, EnvDTE80, EnvDTE90, Extensibility)
- Create a new class implementing IDTExtensibility2
- Copy the debugging properties of a C# based Add-In project into your F# project
- Copy the .AddIn manifest file, and modify it according to your F# project *.. and don't forget to copy that new file in the AddIn directory for the user session
- enjoy!
来源:https://stackoverflow.com/questions/3399637/how-to-create-a-f-based-visual-studio-add-in