It seems that you need to save project:
proj.Save();
before saving solution.
I tried it with msvs2010
, so I'm not sure that in msvs2008
it is the same.
문제
I want to create a new project by code, and add some dll references to my project.
Here is my code
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");
But when I open the project and look in "references" there isn't any Testfile.dll added. What am I doing wrong?
해결책
It seems that you need to save project:
proj.Save();
before saving solution.
I tried it with msvs2010
, so I'm not sure that in msvs2008
it is the same.
다른 팁
Try this:
sln.Projects[0].References.Add(@"C:\testfile.dll");