简体   繁体   中英

Run a c# console application in build process

Suppose we have a solution with three projects:

在此输入图像描述

  1. DownloadDataBase is a console application that downloads data from web and creates a sqlite db file
  2. Test is the main windows from application that uses the downloaded sqlite database.
  3. TestLibrary is a class library that is referenced by the Test project.

I know How I can reorder the build of these three projects using Configuration Manager from build menu. But The main question is : How can I customize build process of the solution so that:

  • It first builds the DownloadDataBase
  • Then executes this console application DownloadDataBase
  • After that copy the created sqlite file from the last step to the resource directory of the Test Project
  • And Finally builds the Test project using the updated sqlite file?

Therefore every time that I build the new release I will have the latest data needed by my application.

Thanks for any help

You'll need to customize your MSBuild project files (ie .csproj files).

For example, in your DownloadDatabase project, add at the bottom of the XML file, inside the <project> element:

<Target AfterTargets="AfterBuild">
    <Exec Command="$(ProjectDir)$(OutputPath)$(AssemblyName).$(OutputType)" />
    <Copy SourceFiles="$(ProjectDir)$(OutputPath)file.db" DestinationFolder="$(SolutionDir)Test" />
</Target>

Maybe there's some mistake, but at the end of the day, you need to use MSBuild tasks to perform these actions.

See Exec and Copy MSBuild task documentation pages to get further details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM