Kabrinskiy Eduard - Azure devops nuget - Kabrinskiy Eduard
<h1>Azure devops nuget</h1>
<p>[youtube]</p>
Azure devops nuget <a href="http://remmont.com">American newspapers headlines</a> Azure devops nuget
<h1>The Code Manual </h1>
<p>Make everything with code</p>
<h1>Caching (not only) NuGet packages on Azure DevOps</h1>
<p>The goal of Cache@2 task is improving build performance by caching files between pipeline runs. It supports multiple types of packages like</p>
<p><ul>
<li>Bundler gems</li>
<li>npm packages</li>
<li>Yarn packages</li>
<li>NuGet packages</li>
<li>Maven artifacts</li>
<li>Gradle artifacts</li>
<li>ccache artifacts</li>
</ul>
</p>
<p>Further, we will focus on caching NuGet packages however in a similar manner we can configure this task for other types.</p>
<h3>Locking dependencies</h3>
<p>Before we configure cache task we need to lock dependencies to create packages.lock.json file as we need that file to set a proper key for the cache. To do that we need to set MSBuild property RestorePackagesWithLockFile for a project.</p>
<p>On the next dotnet restore a lock file packages.lock.json will be generated. We need to store that file in source control to be able to use cache task. However this is not such easy as it looks like. Because, if you use this file probably you will get on CI server error NU1403:</p>
<p>This is because we can get different on different machines/systems. So hash on my machine is different than on Linux host agent or Windows host agent. On github you can find the proposed solution. But this boils down to putting these commands:</p>
<p>in your pipeline. In general, it is really strange that mechanism which should provide a consistent and reliable way of getting the same packages regardless you compile your source code requires to generate on each machine/system a new lock file. I took a different approach. I created the lock file on the host agent and published it as an artifact. Then I downloaded it and committed into source control. I know that it requires to reproduce that step over and over again when I add or update package. But for me, this is a better approach than removing and recreating lock file by CI server. If you want to do the same, you can achieve this using these steps:</p>
<p>Once you create a lock file, you can disable these steps.</p>
<h3>NuGet packages location</h3>
<p>To configure cache task we need also packages location. Following this documentation you can assume that NuGet downloads packages to $(Pipeline.Workspace)/.nuget/packages . But this is wrong or some configuration part is missing like overriding default location for global-packages. If you list $(Pipeline.Workspace) you will find that there is no NuGet folder.</p>
<p>To find nuget packages folder, we can use this command dotnet nuget locals global-packages -l which allow us to set proper path programmatically.</p>
<p>What is worth noted here, that it works for both Linux and Windows host agents.</p>
<h3>Configuration for NuGet packages</h3>
<p>Putting all together:</p>
<p>Looking into cache task logs, you may find that your key was resolved to nuget|"Linux"|h6yiwZzAgkoiZL06WJLdgZToQpsZmeUIUL5u0xFpYHM= , where last part is a hash of your lock file. It means that each time when the lock file will change, a new cache key will be created. In the first run, you may also find information that There is a cache miss . This is because setting cache takes a place in post-job task</p>
<p>In the next run, cache task gets a hit and download packages to the given folder.</p>
<p>Cache task set also variable CACHE_RESTORED to true which causes evaluating condition in next step as false. So we do not restore packages.</p>
<h2>Caching npm modules</h2>
<p>Cache task allows caching not only NuGet packages but also npm modules. For this case I didn?t find any issue following documentation and thus adding that to your build is straightforward as this code snippet:</p>
<p>My angular project is located in the cache-npm subfolder and this is wahy I had to add this to key input in cache task and the working directory of script task.</p>
<p>You may notice that we use npm ci command instead of typical npm install . There is a significant difference between these two. npm install asks bout each module from dependencies and then it upgrades or not. npm ci deletes all node_modules directory and copies them from the cache. Thus you should avoid caching npm_modules directory and cache folder cache itself as we did above. There are a few key information (please check documentation) which you should know before you will use npm ci :</p>
<p><ul>
<li>The project must have an existing <b>package-lock.json</b> or <b>npm-shrinkwrap.json</b>.</li>
<li>If dependencies in the package lock do not match those in <b>package.json</b>, <i>npm ci</i> will exit with an error, instead of updating the package lock.</li>
<li><i>npm ci</i> can only install entire projects at a time: individual dependencies cannot be added with this command.</li>
<li>If a <b>node_modules</b> is already present, it will be automatically removed before npm ci begins its install.</li>
<li>It will never write to <b>package.json</b> or any of the package-locks: installs are essentially frozen.</li>
</ul>
</p>
<p>What is important to remember?! npm ci is meant to use in automated environments as CI builds. It may speed up your build but details strongly dependents on how many modules do you have in your dependencies. It is more strict than npm install and thus may help us keeping consistency in our code. But if you want to add/remove/change a module npm install is your choice.</p>
<p>Code for that part you may find here.</p>
<h3>Summary</h3>
<p>Cache task is very useful as it may reduce significantly network calls to get packages. I recommend to use it especially if you have many dependencies. I can only complain about documentation, as for me there were too many things not working as it is written there. Or maybe it is just me and I didn?t understand all the pieces. In that case, my apologies. The code for this you can find on my github.</p>
<h2>Azure devops nuget</h2>
<h3>Azure devops nuget</h3>
<p>[youtube]</p>
Azure devops nuget <a href="http://remmont.com">Current news update</a> Azure devops nuget
<h4>Azure devops nuget</h4>
14 May 2020 - I added section about caching npm modules in Node.js/Angular project The goal of Cache@2 task is improving build performance by caching files b...
<h5>Azure devops nuget</h5>
Azure devops nuget <a href="http://remmont.com">Azure devops nuget</a> Azure devops nuget
SOURCE: <h6>Azure devops nuget</h6> <a href="https://dev-ops.engineer/">Azure devops nuget</a> Azure devops nuget
#tags#[replace: -,-Azure devops nuget] Azure devops nuget#tags#
Эдуард Кабринский
local news
