问题描述
我已经使用了以下由 给出的代码 Ole Preisler . 现在,我想以编程方式添加一些参考新解决方案中的参考资料-例如,使用NLog;
I have used this below code given byOle Preisler. Now i want to add some reference programatically with other references in new solution like -using NLog;
我该怎么办??
code -----
添加对EnvDTE和EnvDTE80的引用,并将此代码段复制并粘贴到consoleApp项目中.这样可以正确地实例化VS,并从模板创建解决方案.
解决方案 soln = System. 激活器 .CreateInstance( 类型 .GetTypeFromProgID( "VisualStudio.Solution" )) 按 EnvDTE. 解决方案 ;
EnvDTE.Solution soln = System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.Solution"))as EnvDTE.Solution;
soln.DTE.MainWindow.Visible = true ;
soln.DTE.MainWindow.Visible =true;
EnvDTE80. Solution2 soln2 = soln as EnvDTE80. 解决方案2 ;
EnvDTE80.Solution2 soln2 = soln as EnvDTE80.Solution2;
字符串 csTemplatePath = soln2.GetProjectTemplate( " ConsoleApplication.zip"" , "CSharp" );
string csTemplatePath = soln2.GetProjectTemplate("ConsoleApplication.zip","CSharp");
soln.AddFromTemplate(csTemplatePath, @" C:\ temp \ FooBar" , "Foo" , false );
soln.AddFromTemplate(csTemplatePath,@"C:\temp\FooBar","Foo",false);
int x = soln.AddIns.Count;
推荐答案
此示例显示了如何添加dll作为对项目的引用
this example shows how to add dll as a referance to project
EnvDTE.Project projectBL = .. (get project in solution)
VSLangProj.VSProject vsprojectBL = projectBL.Object; // project that will be added referance
vsprojectBL.References.Add(Constants.DllPath);
此致
穆罕默德.
这篇关于如何以编程方式创建新的Csharp解决方案(EnvDTE)?有关的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!