简体   繁体   中英

Visual Studio - Git pull various repositories on build

I have a Web Project that is in it's own git repository. It references other projects that are also in their own repositories, but are added to this solution.

Is it possible to do a pull on those other projects as some sort of a build action? Ideally, when building the Web Project, I would want to pull the master branch and update all the other projects automatically so that I don't have to open each one of their repositories manually, one by one, do a pull for each.

There are default "BeforeBuild" targets in MSBuild, see: https://msdn.microsoft.com/en-us/library/ms366724.aspx

This allows you to run whatever "setup" processes you need before the "CoreBuild" target is run. so, you could do something like this in your project:

<Target Name="BeforeBuild">
    <Exec Command="git.exe clone http://some/repo.git" />
</Target>

This of course assumes that git is installed on the machine and available from the system path. you can also use MSBuild "Items" to make this more "dynamic", for example:

<ItemGroup>
    <ReposToInclude Include="//first/repo.git" />
    <ReposToInclude Include="//second/repo.git" />
    <ReposToInclude Include="//third/repo.git" />
</ItemGroup>
<Target Name="BeforeBuild">
    <Exec Command="git.exe clone %(ReposToInclude.Identity)" />
</Target>

An ItemGroup is like an array and the "%" is like a "foreach" statement. So this one Exec will iterate over all the repos and do a git clone, or pull, or whatever it is you need it to do.

Additionally, you may want to look at using "Conditions" which are just like "IF" statements in code. so you can conditionally do a clone or pull based on some criteria.

Hope this helps.

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