I have multiple projects in the same folder, each of them creates a microservice. Each has a separate build and release pipeline. Currently each project is configured so to trigger when code is committed in its own sub folder. I am currently in the process of adding some common code which is used in some of the projects. I would like for a microservice to build and deploy if it uses a library that is being changes.
What is the best way to achieve this?
Ideally, I imagine something like this:
Build task which triggers on root directory -> Use MsBuild to determine if a project needs to build, by checking its dependencies -> Build/Abort.
Is this possible?
If you want to share code in source form and you are using .NET Framework projects, the best (but not optimal) approach that I found is to have the projects in the same folder and put the shared code in a subfolder that you include in both projects. To put shared code in a folder outside the root folder of a project is even worse.
The best approach (IMO) is to share code in compiled (Dll) form (rather than in source form): you can create a DLL with the shared code, package it in a NuGet package, and publish the NuGet package in some internal NuGet repository (for example, you can use the Artifacts feature of Azure DevOps as NuGet repository for your organization). The projects that require the shared code do it through NuGet references. The advantages is that the shared code in Dll/NuGet form can be versioned (not all projects must be updated at the same time for incompatible changes), it can use its own CI pipeline with unit tests, it can use its CD pipeline to publish to the Artifacts repository, etc.
I switched from the former approach to the latter. Much cleaner IMO.
Related
asp.net core 2.2 publish generating lots off DLL in output directory(bin\Release\netcoreapp2.2\publish).
How I can move it to some other folder (bin\Release\netcoreapp2.2\publish\lib) & reference it?
Your question doesn't really make sense, but I imagine you're looking for a way to include a library from one solution in another. This is not the way to do that.
Instead, package your project as a NuGet. Then, you can reference the NuGet package in your other solution's projects. Some people are confused and think creating NuGet packages means having to make them public on the main NuGet repository. While you can of course do that, it's not required. You have a private repo, either through a third-party or deploy your own, or you can simply use a filesystem path or network location as a "repo".
In any case, creating a NuGet package is simple. You simply edit your project properties, go to the "Package" tab, and enable NuGet package creation. Fill in the relevant details about your package on that screen, and you're off to the races. Whenever you build or publish your project, you'll get a NuGet package created in the same directory. Then, just push that to your NuGet repo, or if it's a filesystem path or network location, copy it there.
I have a shared resources project that I'd like to reference as part of my Team Services build, is there an existing task that can obtain these assemblies so that they are available to the MSBuild task?
I know I can have a libraries folder within a project to hold these references but I'd rather build from a central source and not have the noise of these additional folders in my projects.
Don't put binary references in source control. Turn your binary references into NuGet packages and allow your build process to restore the appropriate version of your NuGet package as necessary.
There is a VS Team Services extension for Package Management that will likely help you accomplish this. You can publish the outputs of your shared project as a private NuGet feed and then consume the feed in your other projects.
These references may also help:
Conceptual - https://www.visualstudio.com/sl-si/docs/package/what-is-packaging
Overview - https://www.visualstudio.com/sl-si/docs/package/overview
I've been fiddling with the TFS2015 task based build system for a few days now. The problem I keep on running into is the following:
I am trying to use nuget packages for my external references in my projects. These exernal references are actually not 3rd party libraries but simply other (shared) libraries of our company. I'm able to restore the packages in a task, but I can't figure out how i can make the "Visual studio Build" understand where to find the restored packages. It uses the hintpath in the project file to determine the location of the external libraries to include. However, these paths (which are used locally for development) don't match the paths used on the build server. I can add a referencepath to the msbuild parameters, but this path isn't searched recursively, and the nuget package restore restores packages including the entire folder structure of the package.
My question is. Is there a proper way to make the "Visual Studio build" step understand the location of my packages without changing the hintpath in the project file. If not, what is the normal way to go here. Should I move away from nuget altogether because our references are not actually 3rd party libraries, and if so, what is the alternative way of resolving the references (without adding the binaries to source control)
My question seems to be related to Storing nuget packages in alternate location on build server, however he seems to have fixed it using a copy to the location that is specified in the hintpath of the references, which is not an option for me. It seems to me there should be an easy way I'm not seeing to be able to point msbuild to the correct location for the libraries.
After the task restoring packages, you can add task "Copy Files" to copy the packages to the location "..\packages\lib\lib.dll"
I come from a Continuous Integration and Continuous Delivery (CI-CD) implementation project background for java web applications. Now i am working for a .NET based project. Microsoft technologies is completely new to me. It is using the MsBuild for the build process via Jenkins. I am learning MsBuild at this time. The more i read, the more confused i am with the Microsoft way of doing this.
I noticed that the msbuild is executed for every environment where the app is going to be deployed using various configuration and profiles based on the environment for the deployment. Below are some msbuild commands for 2 different environments (PIE & TEST)
C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\MSBuild.exe" /p:Configuration=PIE /m:4 /nr:false src/myapp.sln
C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\MSBuild.exe" /p:Configuration=TEST /t:Rebuild /m:2 /p:DeployOnBuild=true /p:PublishProfile=TEST src/myapp.sln
C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\MSBuild.exe" /p:Configuration=STAGE /t:Rebuild /p:DeployOnBuild=true /p:PublishProfile=STAGE /m:2 SprintA/src/myapp.sln
i may be wrong, but i feel that the code being deployed to the two environments (when the code progress from PIE to TEST) is being build for each environment which is not the real code progression concept. IMHO, the build is done once and its progressed to subsequent environments for testing/validation as long as there are no bugs in the code. The various environment specific settings are handled via config files inside the package and the containers (tomcat for a java app) are started with the parameters that reads/parse the confif files.
Is there a way to handle this in .NET? The app is deployed in IIS
UPDATE:
The more i do research reading various docs and blogs, i came across the web publishing method using msbuild for each configuration and the deploy/publish profiles. IS this just the standard way that the mass follows for a .net project's CICD?
Yes, this is something Microsoft realized and is enforced using the new Release System.
Basically you have a "process" (Build) building your code and producing artifacts (ie. website file structure, nuget package, installers, etc) in this process you typically take care of things like applying the version value to your assemblies, minifiying js and css files or anything not related with the any specific environment.
Then you have another "process" (Release) to configure your artifacts based on the environment where they will be deployed (ie. modifying web.config files from your website) and deploy those artifacts to the desired environment without having to build them again. (ie. push nuget package to some pre-production nuget feed, copy you website structure to the server, etc)
How do you implement these two "processes"?. Well, that depends on your preference and tools. If you use Visual Studio Team Services you have these processes clearly defined out of the box by the infrastructure, and a lot of built in task to support them.
I have not worked with Jenkins but as long as you can use msbuild you could have 2 msbuild projects one to build your artifacts from the source code on different branches and another one to deploy to different environments base on some configurations (ei. your PIE & TEST) and of course you could use tools like powershell or MSbuild custom tasks to support more advanced scenarios within your processes.
I have a workspace which has 2 projects, one is installer application and other is uninstaller app.
Both the apps requires privilege helper tool for some operations. I am trying to write a common tool as a third project in my workspace that would be linked with the existing projects.
Now, the question is how can i add that common tool in target dependency of existing projects and launch(privilege tool) it from other projects.
You can add the project that contains the helper tool within the other workspaces, and then add the target corresponding to the helper tool as build dependency, as you want.
If however you are using source control and have different repositories for projects, you can use the helper tool repository as a submodule to the other ones. See this article for more on git submodules and how you can use them.