Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将DLL库引用添加到VSX中的项目_C#_Reference_Code Generation_Vsx - Fatal编程技术网

C# 将DLL库引用添加到VSX中的项目

C# 将DLL库引用添加到VSX中的项目,c#,reference,code-generation,vsx,C#,Reference,Code Generation,Vsx,我想通过代码创建一个新项目,并向我的项目添加一些dll引用 这是我的密码 System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.9.0"); object obj = System.Activator.CreateInstance(type, true); EnvDTE.DTE dte = (EnvDTE.DTE)obj; Solution2 sln = (Solution2)dte.Solution; sln.Cr

我想通过代码创建一个新项目,并向我的项目添加一些dll引用

这是我的密码

System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.9.0");
object obj = System.Activator.CreateInstance(type, true);
EnvDTE.DTE dte = (EnvDTE.DTE)obj;
Solution2 sln = (Solution2)dte.Solution;
sln.Create(@"C:\tmp", "TestSolution");
string templatePath = sln.GetProjectTemplate("WindowsApplication.zip", "CSharp");
sln.AddFromTemplate(templatePath, @"C:\tmp\Project", "TestProject", false);
Project proj = sln.Projects.Item(1);
VSProject2 vsproj = (VSProject2)proj.Object;
vsproj.References.Add(@"C:\testfile.dll");
vsproj.Refresh();
sln.SaveAs("TestSolution");
但是当我打开项目并查看“引用”时,没有添加任何Testfile.dll。我做错了什么?

试试这个:

 sln.Projects[0].References.Add(@"C:\testfile.dll");
看来你需要:

proj.Save()

在保存解决方案之前


我用
msvs2010
试过了,所以我不确定在
msvs2008
中是否相同。

当我尝试上述操作时,我得到了以下错误消息:无法将带[]的索引应用于“EnvDTE.Projects”类型的表达式嘿,酷!谢谢您知道是否可以从项目中删除引用吗?@Mathias@Mathias有帮助吗?