如何以编程方式创建新的Csharp解决方案(EnvDTE)?有关的 [英] How to create new Csharp Solution, Project programmatically ( EnvDTE ) ?? related

查看:76
本文介绍了如何以编程方式创建新的Csharp解决方案(EnvDTE)?有关的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

 我已经使用了以下由 给出的代码 Ole Preisler . 现在,我想以编程方式添加一些参考新解决方案中的参考资料-例如,使用NLog;

 

  I have used this below code given by Ole 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( 类型 "VisualStudio.Solution" )) EnvDTE. ;

     EnvDTE.Solution soln = System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.Solution")) as EnvDTE.Solution;

true ;

soln.DTE.MainWindow.Visible = true;

Solution2 soln2 = soln as EnvDTE80. ;

EnvDTE80.Solution2 soln2 = soln as EnvDTE80.Solution2;

csTemplatePath = soln2.GetProjectTemplate( " ConsoleApplication.zip"" "CSharp" );

string csTemplatePath = soln2.GetProjectTemplate("ConsoleApplication.zip", "CSharp");

@" C:\ temp \ FooBar" "Foo" false );

soln.AddFromTemplate(csTemplatePath, @"C:\temp\FooBar", "Foo", false);

x = soln.AddIns.Count;

推荐答案

ShailiShah,

Hi ShailiShah,

此示例显示了如何添加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)?有关的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆