Invoke EntityDeploy build task programmatically

后端 未结 2 1387
名媛妹妹
名媛妹妹 2021-02-14 19:11

I\'m using Roslyn to compile, emit and run C# source code. However, I\'ve run into a limitation when faced with projects that use EntityFramework.

It seems that simply e

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-14 19:55

    Try the following:

    var mockObject = new Mock();
    IBuildEngine engine = mockObject.Object;
    
    var entityDeployTask = new EntityDeploy();
    entityDeployTask.Sources = new ITaskItem[] 
    {
      new TaskItem(@"path to edmx\Model1.edmx")
    };
    entityDeployTask.OutputPath = @"C:\";
    entityDeployTask.BuildEngine = engine;
    entityDeployTask.Execute();
    

    The output path doesn't seem to be picked up, but if it's empty then an error is logged. You can see this if you implement your own IBuildEngine and log the errors. The result of the process will be three files next to the edmx: "Model1.ssdl", "Model1.csdl", "Model1.msdl". These files need to be passed to CSC as embedded resources, at least that's what the original targets file seems to do.

    Hope it helps, and at least gets you started.

提交回复
热议问题