I have ASP.NET Core Web API
project and .Net Core Library
project. The Web API has reference to Library project as target : project
. Name of the library project is Transformations
.
Below is the project.json for both the projects
project.json for Web API
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Transformations": {
"target": "project"
},
"Microsoft.Extensions.DependencyInjection": "1.0.0",
"Serilog.Extensions.Logging": "1.3.0-dev-10125",
"Serilog.Sinks.RollingFile": "3.0.0",
"Serilog.Settings.Configuration": "2.1.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0"
},
project.json for Library project
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"configurations": {
"Production": {},
"Staging": {}
}
}
On the build server below is the project structure for Api & Transformation projects.
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution
\Api
\Transformation
On the build server I executed the following commands
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet restore
and then
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet build
I get error
Project Transformations does not have a lock file. Please run "dotnet restore" to generate a new lock file.
Now if I run the following the following commands in the order, then everything works fine.
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Transformation>dotnet restore
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet restore
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet build
Questions
1>When library is referenced as project in API project why do I need to run dotnet restore
separately for library project? Why cant it restores
referened project implicitly?
From Zlatko Knezevic:
This behavior is by design. […] If you wish to restore all of the dependencies for all your projects in one go, so to speak, just run
dotnet restore
at the root of your solution (where you have theglobal.json
file).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With