我正在使用 Roslyn 来编译、发出和运行 C# 源代码。但是,在面对使用 EntityFramework 的项目时,我遇到了限制。
似乎简单地发出编译是不够的,因为有一个EntityDeploy
在 DLL 发出后对其进行操作的构建任务。 (我相信它在发出后将元数据工件嵌入到 DLL 中)。
In the .csproj
在我正在处理的文件中,我看到以下实体部署任务:
<EntityDeploy Include="Models\Northwind.edmx">
<Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>Northwind.Designer.cs</LastGenOutput>
</EntityDeploy>
是否可以直接调用此构建任务并操作我发出的 DLL?
Note:我不想简单地打电话msbuild.exe
or run 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
and EntityDeploy
,所以如果我误用了术语或完全错误地理解了这一点,请纠正我。