Auto update nuget package from a local folder - asp.net-core

My .NET Core project references a class library from another project.
I publish the nuget package to a local folder like this:
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration% -o D:\\mynugetpackages\\%project:Name%"
]
}
Then I add a reference to another project from this folder.
Every time I update my class library, I have to manually go to manage nuget packages and then update nuget packages from Visual Studio in the referencing project.
Is there a way to automate this, so that when I make an update and publish latest nuget package, the referencing project will automatically update to the latest update?

No, it's not possible for Visual Studio to automatically detect that a package has been updated (in a local or remote source).
You could write a script to run nuget update in your target project to grab the latest packages, but you'd still likely have to kick off the script manually. This would at least be faster than manually clicking through the NuGet GUI in Visual Studio.
Another option is to put the class library in the same solution folder structure as your main project, and reference it as a project dependency:
"dependencies": {
"MyClassLib": {
"target": "project"
}
}
This only works if you're able to adopt this folder structure, though:
src/
MyProject/
MyClassLib/

Related

Deploying service fabric Visual studio build failing

I am trying to run the "Visual studio build task" in VSTS CI, but its failing with the following error:
Build error
I read it here bclbuildWhat does the Microsoft.Bcl.Build NuGet package do?
and passed the MSBuild arguments as /p:BclBuildImported=Ignore but still it complains that nuget restore didn't occur. What could be the problem?
Nuget restore task:
Nuget-restore task
Firstly make sure you can build the project locally with VS. Then add Nuget Restore task in the build definition to restore the packages.
UPDATE:
Just check your Nuget.config file, make sure you have set the correct feeds/package sources you want to consume and the package Microsoft.Bcl.Build.1.0.21 is included in the sources.
See Specifying sources in NuGet.config for details.
Besides, you can also try to create a new build definition with the Nuget restore task, then provide the nuget.config file and proper path to solution, also try with other Hosted agents.

Visual Studio Team Services Continuous Integration: NuGet Restore Task Failed

I am using Continuous Integration feature in Team Services (was Visual Studio Online). My build definition targets a specific project in a solution (not the whole solution), which is ClientUI MVC website.
The solution contains three projects:
ClientUI
AdminUI
Client Services
The Build Definition for ClientUI Project:
Repository:
Nuget Installer Step:
I have tried different params but not working.
Visual Studio Build
Before trying to target the a single project, my build definition was targeting the whole solution with the following parameters:
NuGet Installer -> Path to Solution: **\*.sln
Visual Studio Build -> Solution: **\*.sln ; MSBuild Arguments: /p:outdir=$(build.artifactstagingdirectory)
It was working. However now, it generates this error in the Nugget Restore Task:
2016-04-22T21:07:00.6716725Z Set workingFolder to default: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\tasks\NuGetInstaller\0.1.25
2016-04-22T21:07:00.8163908Z Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\tasks\NuGetInstaller\0.1.25\NuGetInstaller.ps1
2016-04-22T21:07:01.5283529Z ##[error]Cannot find path 'C:\a\1\s\packages.config' because it does not exist.
2016-04-22T21:07:01.5439897Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\agent\worker\tools\NuGet.exe restore "C:\a\1\s\packages.config" -NonInteractive
2016-04-22T21:07:03.0441507Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2016-04-22T21:07:03.0597010Z ##[error]Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
2016-04-22T21:07:03.0909881Z ##[error]Unexpected exit code 1 returned from tool NuGet.exe
Try setting "Installation type" to "Install" for "Nuget Installer" task since you are using "packages.config" to install the packages.
For anyone curious, the source of the error about "Please specify either -PackagesDirectory or -SolutionDirectory" is that the build process is trying to issue a command similar to this:
C:\hostedtoolcache\windows\NuGet\4.4.1\x64\nuget.exe restore D:\a\1\s\MyProject\packages.config -PackagesDirectory packages -Verbosity Detailed -NonInteractive
The below screenshots should help if you want to build a project (rather than the solution) and your nuget "packages" folder is at the solution-level.
Additionally, you may need to specify this as the "MSBuild Argument" in the build task of your project: /p:SolutionDir="/"
I had the same thing sorted it out by changing the mapping - go to Repository tab, I had my mapping to another directory which means the nuget installer could not execute.

Referencing package path in VSO with DNX projects

I have to reference the test adapter DLL (xunit.runner.visualstudio.testadapter.dll) in our vNext Visual Studio Online build to execute the tests.
The problem is that with the new DNX structure, packages are being restored to C:\Users\{user}\.dnx\packages and are not relative to the project's path anymore.
How can I reference this location in the build?
We are using the hosted build agent.
I think the answer for your question can be found in the following StackExchange answer: Running unit tests in TFS/VSO Build vNext using xUnit adapter. Then the packages end up in a local directory and not the global .dnx cache.
...
Make a global.json file and put the following into it:
{
"packages": "packages"
}
That will force your dnu restore to put the packages into .\packages\, which will hopefully solve the problem.

Managing dependencies in vnext

At the company I work at we do the following when we need references to third party dlls in our projects:
Use nuget to get package
Pull dll's out and create a "lib" folder and add the references here
this lib folder is added to git so other team members have all references when they do a pull from git
Reference dll's stored in lib folder in our project
We do this to have full control and know exactly what references we are using.
My question is how is this achieved when using vnext and can we continue to do it this way?
Have watched "INTRODUCING: The Future of .NET on the Server" and it seems you list all dependencies in project.json file and when you do k restore it will go and download all based on feeds in nuget config file
You'll make use of the project.json file. As you mentioned, you list all your dependencies in there and the K Package Manager will deal with resolving the missing packages for you.
You'll notice that in the json file you specify the package in somewhat of a key-value pair of package:version. Most examples show a version of * which means get me the latest. But there's nothing stopping you from specifying a specific version, or a specific part of a version. For instance, the project.json file in the Autofac container of the DI project specifies a specific version of Autofac:
"dependencies": {
"Autofac": "3.3.0",
"Microsoft.Framework.DependencyInjection": ""
},
The main DI project specifies a sort-of-specific version of Microsoft.Framework.ConfigurationModel:
"dependencies": {
"Microsoft.Framework.ConfigurationModel": "1.0.0-*"
},
That says get me the most recent build of 1.0.0
This system allows you to automatically get the latest and greatest if you want, but also specify a specific version for safety. There's no reason to copy DLL's into a custom lib folder.
EDIT: You inspired me to blog about it: http://davidzych.com/2014/08/13/specifying-package-dependency-versions-in-asp-net-vnext/
Just noting that "-*" does not necessarily return the latest version. It my simple testing, it always returns the lowest available version. Per this documentation the calculation is more complex and returns the lowest version that "works".
EDIT: added link to documentation

TFS 2012 - binary files are not generated when using automatic build

I am newbie to TFS.
I am trying to automate process of build upon checking in the code in TFS.
I setup a Controller and an Agent. I created a new build definition and set a "build" and "drop" folder on c:.
I check in the code, expecting to see the generated dll files in "drop" folders. There's none, just "logs" folder. The "binaries" folder in "build" folder is also empty. Apparently the binaries are not being generated at all. How can I have MSBuild to generate the dll files?
They are generated when I compile the website locally on my development machine under "bin\" folder. The solution is comprised of two separate projects: "core" and "web" where "core" is referenced within "web".
Any thoughts?
What is the Summary showing of your build that ran? Or are there errors in your build? You can check the log of the build by opening the build in Visual Studio and then click View Log.