Visual Studio 2008 template containing both a C# and a C++/CLI project?
I'm currently writing a Winamp plug开发者_运维知识库in framework for C# (basically, a C# implementation of the Winamp API/SDK, as well as a barebones plugin template). Because C# libraries can't export DLL entry points, I'm using a C++/CLI wrapper which basically just loads the C# library. I'd like to create a Visual Studio template for this, which creates both the barebones C# plugin library, and the C++ wrapper. However, if I click File → Export Template, only the C# project is listed.
Is it possible to create a multi-project template containing both a C# project and a C++/CLI project? If so, how?
I found the answer myself a while ago, and forgot to properly update this. A .vstemplate file can be used to create a C++ template by setting the language to CSharp like in C# templates (it will still work correctly).
Here is an example I've used: .vstemplate file and all other files
WiX also uses this method
'export template' does not work for C++ projects. If you want templates for them, you need to create it yourself: see my answer here. It involves some work, but if you use this kind of projects a lot, the work is well-spent time.
edit
I looked up my code, something like this should get you started; the onFinish method in default.js gets called after clicking 'Ok' in the default wizards. Note that I did not test this!
function onFinish( selProj, selObj )
{
var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
var prjCpp;
var prjCs;
CreateProjects( strProjectPath, prjCpp, prjCs );
//project config here
prjCpp.Object.Save();
prjCs.Object.Save();
selProj = prjCpp;
}
function CreateProjects( path, prjCpp, prjCs )
{
var strProjTemplatePath = wizard.FindSymbol('ABSOLUTE_PATH'); //get template from our template dir
var strProjTemplateCpp = strProjTemplatePath + '\\default.vcproj';
var strProjTemplateCs = strProjTemplatePath + '\\default.csproj';
var Solution = dte.Solution;
if( wizard.FindSymbol( "CLOSE_SOLUTION" ) )
{
Solution.Close();
strSolutionName = wizard.FindSymbol( "VS_SOLUTION_NAME" );
if( strSolutionName.length )
{
var strSolutionPath = strProjectPath.substr( 0, strProjectPath.length - strProjectName.length );
Solution.Create(strSolutionPath, strSolutionName);
}
}
var oTarget = wizard.FindSymbol( "TARGET" );
prjCpp = oTarget.AddFromTemplate( strProjTemplateCpp, strProjectPath, strProjectName + '.vcproj' );
prjCs = oTarget.AddFromTemplate( strProjTemplateCs, strProjectPath, strProjectName + '.csproj' );
Solution.Projects.Add( prjCpp );
Solution.Projects.Add( prjCs );
}
精彩评论