我想在我的解决方案中动态创建项目
C#代码
protected void Page_Load(object sender, EventArgs e)
{
string projectPath = @"C:\Users\lucas_000\Documents\Visual Studio 2010\Projects\ModelingProject1\ModelingProject1\ModelingProject1.modelproj";
using (IModelingProjectReader projectReader = ModelingProject.LoadReadOnly(projectPath))
{
IModelStore store = projectReader.Store;
foreach (IClass umlClass in store.AllInstances<IClass>())
{
try
{
Engine engine = new Engine();
//engine.BinPath = RuntimeEnvironment.GetRuntimeDirectory();
Project project = engine.CreateNewProject();
project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets", null);
BuildPropertyGroup props = project.AddNewPropertyGroup(false);
props.AddNewProperty("AssemblyName", "myassembly");
props.AddNewProperty("OutputType", "Library");
BuildItemGroup items = project.AddNewItemGroup();
items.AddNewItem("Reference", "Some.Assembly");
items.AddNewItem("Compile", "somefile.cs");
project.Save("myproject.csproj");
}
catch (Exception e2)
{
}
}
}
}
问题
什么时候保存项目,UnauthorizedAccessException
出现在我不想要的文件夹中保存这个新项目。
如何在Visual Studio 2010中的当前解决方案中创建此项目?
更新
专栏project.Save("myproject.csproj")
尝试保存在C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\myproject.csproj
我所有的解决方案都在C:\Users\lucas_000\Documents\Visual Studio 2010\Projects