我正在使用Roslyn来编译、发出和运行C#源代码。然而,当遇到使用EntityFramework的项目时,我遇到了一些限制。
似乎仅仅发出编译不够,因为有一个名为
在我处理的
这个构建任务是否可以直接调用并操作我发出的DLL呢?
注意:我不想简单地调用 msbuild.exe 或者 运行 MSBuild 来处理 .csproj 文件中的所有内容。我正在内存中构建项目,而不是在磁盘上,所以这种方法在我的情况下不适用。
我尝试过使用Microsoft.Build.Evaluation 工具来进行实践。我能找到 EntityDeploy 任务,但是我不知道如何调用它(以及我应该提供哪些参数)。
似乎仅仅发出编译不够,因为有一个名为
EntityDeploy
构建任务会在发出后操作DLL文件。(我相信它是在发出后将元数据工件嵌入DLL中)。在我处理的
.csproj
文件中,我看到以下实体部署任务:<EntityDeploy Include="Models\Northwind.edmx">
<Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>Northwind.Designer.cs</LastGenOutput>
</EntityDeploy>
这个构建任务是否可以直接调用并操作我发出的DLL呢?
注意:我不想简单地调用 msbuild.exe 或者 运行 MSBuild 来处理 .csproj 文件中的所有内容。我正在内存中构建项目,而不是在磁盘上,所以这种方法在我的情况下不适用。
我尝试过使用Microsoft.Build.Evaluation 工具来进行实践。我能找到 EntityDeploy 任务,但是我不知道如何调用它(以及我应该提供哪些参数)。
var project = new Project(@"C:\Users\JoshVarty\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\WebApplication1.csproj");
//Get the entity deploy target? I'm not sure if this is a task or target.
var entityDeploy = project.Targets.Where(n => n.Key == "EntityDeploy").Single();
var projectTargetInstance = entityDeploy.Value;
我也尝试查看磁盘上存在的EntityDeploy
构建任务。
var entityDeployTask = new Microsoft.Data.Entity.Build.Tasks.EntityDeploy();
entityDeployTask.Sources = //I'm not sure where I can get the ITaskItem[] I need
entityDeployTask.EntityDataModelEmbeddedResources = //I'm not sure where I can get the ITaskItem[]
entityDeployTask.Execute();
我同时对MSBuild
、EntityFramework
和EntityDeploy
都是新手,如果我使用术语不当或者完全错误,请纠正我。