1
votes

Since VSTS has sought to bend to the popular Git source control, I have yet to see a good description of building .Net projects located in Git repositories, having project dependencies on one another.

For instance, in Visual Studio, I build a solution that includes projects with dependencies on each other. Then, in VSTS each of those .Net projects are versioned in separate Git repositories.

How, then, do you get a build on VSTS? How do you get the artifacts (read: DLLs) from one project into the project of the other?

UPDATE: 12/18/17 I took @VonC's suggestion and followed-through on a VSTS (Visual Studio Team Services) hosted Nuget package. I was able to make this work. This process makes .Net solution files and project dependencies OBSOLETE.

If you want to reuse a library, you can save the binaries as a NuGet package.

In the downstream project, you simply assign the VSTS url reference to the Nuget package to get the Nuget Restore to find/place the binaries in your build project.

You will have to download and install a Credentials tool that will allow you to push your binaries to VSTS's package location. Additionally, tell your admin to add the Packages functionality from the VSTS Marketplace.

Thanks, @VonC for the great suggestion!

Here are some helpful links:

3

3 Answers

0
votes

The idea is, for binary dependencies (DLLs) to not involve a source control tool (like Git) but a binary referential one (like Nuget)

See for instance:

With Visual Studio 2017 and .NET Core, we have improved the NuGet package management experience by introducing the PackageReference feature in MSBuild.
PackageReference brings new and improved capabilities such as deep MSBuild integration, improved performance for everyday tasks such as install and restore, multi-targeting and more.

https://blog.nuget.org/images/2017-03-16-NuGet-now-fully-integrated-into-MSBuild/pr-in-action.png

0
votes

First, it’s unnecessary to manage the build artifacts (such as dlls) in source control since they're the output files from the source code.

Then to add dependencies (dlls) from other repos to the parent (main) repo’s project, there usually has below options:

Option 1: manage the build artifacts as packages

As Vonc mentioned, you can manage the dlls as nuget packages, and then add nuget packages to your main repo’s project.

Option 2: git submodules

You can also treat other repos as the submodules for the main repo, and both build the projects from the submodules repos and the main repo in the build, then the main repo project can get the dependencies from the submodule repos’ build artifacts.

Commands to add a submodule for the main repo:

# In local main repo
git submodule add <URL for a submodule repo>
git commit -m 'add a submodule'
git push

Note: in VSTS build definition, you should select checkout submodules in Get Sources step.

Details about git submodules, you can refer Submodules.

Option 3: git subree (alternative way for git submodules)

Treat a branch from another repo as a subtree (a folder) in the main repo. Then build the projects both in the main repo and the subtrees, and get dependencies from subtrees for the main repo’s project.

Commands to add a subtree in the main repo:

git submodule add --prefix=submodule1 <URL for sub repo> master
git push

Then it will add a folder submodule1 with the files in the sub repo master branch, and commit the changes in the main repo.

Details about git subtree, you can refer Git subtree: the alternative to Git submodule.

-1
votes

At any time, if your branch has working code with any version of dependent assemblies, I can't see any reason you need to do anything.

For example of dependencies here: enter image description here

You can set dependencies in project like:

enter image description here enter image description here enter image description here

Also you can add dependencies in solution like :

enter image description here

You can set build order in solution too if your project has multiple project with dependencies.

As long as your current code in branch from which you are build is working (with any version of different assemblies, e.g. Classlibrary1 has version 1.0.0.0, Classlibrary2 has version 1.2.2.1 & so on but is working fine with each other after referencing) this approach will work.

Project dependencies exist for ages in Visual Studio & .Net. As long those project exist in same TFS branch You can add project dependency right in dependent project. Also you can manage Project build order in Solution.

For more complex scenarios like different repositories or branch dependencies you need to modify build workflow but it is also quite possible.

You can also refer http://dailydotnettips.com/2015/11/25/how-to-identify-the-project-dependencies-in-visual-studio/ what I saw long time ago when I created same sample for test.