# How to run Entity Framework Migrations using MSBuild and Migrate.exe

**URL:** <https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293>\
**Category:** Discussion\
**Created:** [December 15, 2014, 1:23am UTC](https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293 "2014-12-15T01:23:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pravins](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/5daacb/32.png) [@pravins](https://www.finalbuilder.com/forums/u/pravins)\
**Post date:** [December 15, 2014, 1:23am UTC](https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293/1 "2014-12-15T01:23:47Z")

</div>

hi,  
I want to run entity framework migrations using MSBuild and migrate.exe in continua CI.  
  
But some how i am not able to copy migrate.exe from "&nbsp;$Workspace$\Source\GitRepository\packages\EntityFramework.6.1.1\tools " path to&nbsp;$Workspace$\Output folder.  
  
I am using below link for reference,  
[http://www.gitshah.com/2014/06/how-to-run-entity-framework-migrations.html](http://www.gitshah.com/2014/06/how-to-run-entity-framework-migrations.html)  
  
Does anyone have idea about how we can&nbsp;achieve this in Continua CI.  
  
Thanks in advance.  
&nbsp;

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [December 16, 2014, 3:52am UTC](https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293/2 "2014-12-16T03:52:45Z")

</div>

Hi,  
  
You should be able to use Copy action to copy the migration tool. Set the Source Directory to&nbsp;$Workspace$\Source\<span style=“background: #ffffff;”\>GitRepository\packages\EntityFramework.6.1.1\tools, the File Names / Patterns to \*.exe and Destination Path to&nbsp;$Workspace$\Output. Then use an Execute Program action to run $Workspace$\Output\Migrate.exe with the name of your dll or exe as an Argument.  
  
If you have tried this and it has not worked then first enable logging for repository rules and workspace rules and then send the build log to [support@finalbuilder.com](mailto:support@finalbuilder.com), along with&nbsp;details of the relevant action settings, your repository settings, the workspace and repository rules, and any errors in the event log.

---

<div class="post-metadata">

**Author:** ![pravins](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/5daacb/32.png) [@pravins](https://www.finalbuilder.com/forums/u/pravins)\
**Post date:** [December 16, 2014, 9:53am UTC](https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293/3 "2014-12-16T09:53:06Z")

</div>

hi,  
  
thanks for your reply.  
  
Now I am able to copy migrate.exe to output folder And also tried to run that exe using MSBUILD action but getting below error,  
  
MSBUILD : error MSB1009: Project file does not exist.&nbsp;  
Switch: C:\CI\_WS\Ws\177\Output\migrate.exe Migration.Data.dll&nbsp;&nbsp;  
  
So not sure whether its possible to pass exe file in Project File text box of MSbuild Action.  
  
Or Is there any other way to achieve this?&nbsp;

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [December 17, 2014, 1:24am UTC](https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293/4 "2014-12-17T01:24:59Z")

</div>

There’s a few ways to do this:  
  
**Option 1:** As in my previous reply, you add three Continua actions:&nbsp;

`Copy action `

`    ``Source Directory: $Workspace$\Source\GitRepository\packages\EntityFramework.6.1.1\tools`

`    ``File Names / Patterns: *.exe `

`    ``Destination Path: $Workspace$\Output`

`MSBuild action`

`    ``Project File: $Workspace$/Source/GitRepository/Migration.Data.csproj`

`    ``Output Path: $Workspace$\Output`

`Execute Program action`

`    ``Executable Path: $Workspace$\Output\Migrate.exe`

`    ``Working Directory: $Workspace$\Output`

`    ``Arguments: Migration.Data.dll`

   
  
**Option 2:** &nbsp;.First edit your project file e.g. Migration.Data.csproj and add the following Target:  
  

`<``Target` `Name``=``“Migrate”``>  `

`    ``<``exec` `Command``=``"$(OutputPath)\migrate.exe Migration.Data.dll /verbose"``/>  `

```Target``>`

  
Then add&nbsp;two Continua actions:&nbsp;  
  
 

`Copy action `

`    ``Source Directory: $Workspace$\Source\GitRepository\packages\EntityFramework.6.1.1\tools`

`    ``File Names / Patterns: *.exe `

`    ``Destination Path: $Workspace$\Output`

`MSBuild action`

`    ``Project File: $Workspace$/Source/GitRepository/Migration.Data.csprojTargets: build;migrate`

`    ``Output Path: $Workspace$\Output`

  
  
**Option3:** First edit your project file e.g. Migration.Data.csproj and add the following Target:  
  

`<``Target` `Name``=``“Migrate”``>  `

`    ``<``copy` `SourceFiles``=``"$(MigratorToolPath)\migrate.exe"` `DestinationFolder``=``"$(OutputPath)"` `/>`

`    ``<``exec` `Command``=``"$(OutputPath)\migrate.exe MigrationsDemo.exe /verbose"``/>  `

```Target``>`

  
Then add one Continua action:&nbsp;  
 

`MSBuild action`

`    ``Project File: $Workspace$/Source/GitRepository/Migration.Data.csproj`

`    ``Output Path: $Workspace$\OutputTargets: build;migrate`

`    ``Properties: MigratorToolPath=$Workspace$\Source<span style=“color: #000000; background: #f8f8f8;”>GitRepository</span>packages\EntityFramework.6.1.1\tools`

---

<div class="post-metadata">

**Author:** ![pravins](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/5daacb/32.png) [@pravins](https://www.finalbuilder.com/forums/u/pravins)\
**Post date:** [December 17, 2014, 2:47am UTC](https://www.finalbuilder.com/forums/t/how-to-run-entity-framework-migrations-using-msbuild-and-migrate-exe/5293/5 "2014-12-17T02:47:53Z")

</div>

Thanks a lot.
