I have a C# solution which contains 3 projects; Application.Server, Application.Client, and Application.Common. Both server and client have a project reference to common.
I want to pack server and client up so that they can be used by other teams in my organisation. I have some automated build pipeline set up that do so, and they publish the nuget packages for server and client. They do not package or publish common. When I inspect the nuget packages, I can see that they reference the common package.
Is there a way that I can get them to build that project into them self? Ideally I don't want to publish the common package as it's pretty specific to my application, and it doesn't really make sense that it's something that's independently consumable by other departments. I also don't want to have to worry about wrangling extra nuget packages if I can help it (as in reality, Common is actually several projects).
If your projects are "old style"/non-SDK/traditional csproj, AND if any project uses a NuGet package, if all those NuGet references are defined using packages.config, then use you can use nuget.exe pack -IncludeReferencedProjects. However, if any of your projects use PackageReference to define their package references (new, SDK-style projects can only use PackageReference), then nuget.exe pack will not correctly create NuGet dependencies for those packages. For SDK style multi-targeting projects, nuget pack will probably completely fail.
The only supported way to pack projects that use PackageReference, or any SDK style project, is to use NuGet's MSBuild pack target (either dotnet pack or msbuild -t:pack). However, this does not have an equivalent to nuget.exe's IncludeReferencedProjects.
If your projects are SDK style, it really shouldn't be any more difficult to create and publish one package or many packages. Simply run dotnet pack on your solution, and every packable project gets packed (remember to mark any class library project you don't want to become a package as not packable). Then use your favourite scripting language to find and publish all nupkg files. For example (Get-ChildItem -Recurse -Filter *.nupkg $SLN_DIR | ForEach-Object { & dotnet nuget push $_ }, or copy/move all nupkgs to a single place (or use the appropriate setting to make NuGet create the packages there in the first place) and use dotnet nuget push *.nupkg.
The NuGet team recommends one package per assembly, and the tooling automatically creates NuGet dependencies for project references, so it all "just works" out of the box. To create a package with all the assemblies included, instead of NuGet dependencies, requires you to do a bunch of work.
Related
The IT industry loves to create buzzwords, some new, some are new twists on old things. In .NET Core I read about Packages, References, NuGet Packages, DLL files and Namespaces. I understand the simple basics/steps, but is there a consistent relationship between some/all of the above words?
Does a single Reference ALWAYS point to a single Package?
Is one Package ALWAYS made of one DLL?
Is NuGet Package same as a Package?
What is the relationship between DLL file and Packages? 1 to 1, 1 to many? None?
Creating a Reference - is doing what? Is it pointing to ONE Package or Many?
When I use "Using ABC.123.DEF;", am I creating a new Reference? If not, would I already have created a Reference to that? What does Creating a Reference do, includes the DLLs (other files) in my project, or just tells the compiler to do so at compile time?
Finally, what form does MetaPackage take in Core 3? Is it a NuGet Package?
DLL File
A .dll (Dynamic Linked Library) file is a library that contains code and data that can be used by more than one program, each project that uses it adds a reference to it
Nuget Packages
Put simply, a NuGet package is a single ZIP file with the .nupkg extension that contains compiled code (DLLs), when you use Nuget pckage manager console to add packages. if i write a library that would be usefull to other developers, i can publish it to Nuget as a nuget package
Read more about nuget packages
Package Reference
A reference is essentially an entry in a project file that contains the information that Visual Studio needs to locate the component or the service.
for example, if you want to use EntityFramework in your project, you need to install it with the following command
Install-Package EntityFramework
This adds a package reference in the .csproj file
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
Note: versions may vary
I am trying to create Team City build template which requires minimum customisation, and I want it to play nicely with legacy projects and projects developed with .NET Core/Standard and .NET CLI.
I am stuck with NuGet as there were some considerable changes in how things work.
Earlier we had to create nuspec file to pack project as a NuGet package. At least in that file we could define various package-related properties.
New csproj file format allows us to define all package properties inside itself. That's fine, but how then do we know which projects should be packaged and which should not?
So far our TeamCity's build step Pack NuGet just contained **.nuspec for Specification files: field. The very fact of nuspec file presence served like a flag pack & publish this project.
However, for dotnet pack we need to specify the project. There is no simple way to distinguish 'main' projects from 'auxiliary' ones on which mains depend. (Let us ignore that project-to-project references are currently not supported.)
We either could pack all projects specifying **.*proj (yet in that case we are to know which packages to publish) or we might specify projects explicitly in a build configuration, but I don't like this approach because you must edit build configuration each time new project is added to the solution.
I also considered the option Generate package on build and omit dot net pack step as package is created on build. The only thing left is publishing the packages with dotnet nuget push specifying **/%BuildConfiguration%/*.nupkg.
Unfortunately when starting build against solution without projects with enabled Generate package on build makes TC fail complaining that
Target files not found for pattern "**/Release/*.nupkg"
Hence, I either need another recipe for achieving the required result or an advice how to make TC consider empty result just as a NOP and mark build as successful.
Yet another option is to use nuspec even for new csproj...
Since TeamCity 2017.2 will be available option to associate build configuration with multiple templates. So you will be able to create different templates to create packages for old projects and new .NET CLI projects.
To specify paths for target .NET projects, which should be packaged, you could use build configuration parameters.
To set such parameters during the build you could send in the preceding build step service message. The value of this parameter could be set to the list of target project files which could be selected via script like that: https://stackoverflow.com/a/8153857/305875
I created a new asp.net project, and I am using the monodevelop as the ide.
On the left hand side in the explorer I can see two sections, one is called reference and the other called packages.
I assume that references are the library or dependency files like the jar equivalent of java. Then what are the packages section for?
Is it also another kind of dependency?
Can anybody help me understand the meaning of those two sections?
I assume you mean References and Packages. There is no Resources section/folder when I create an ASP.NET project in MonoDevelop.
The References folder will show the assemblies that are being referenced by your project. An assembly is equivalent to a jar file.
The Packages folder shows you the NuGet packages that are being used by your project. A NuGet package will typically provide assemblies and these will be shown inside the References folder but within a From Packages folder. A NuGet package may include other things, such as content files, which are added to the project, or custom MSBuild targets which modify the build behaviour.
I have created a project in VS2015, structure as below:
Solution1
BookStore.ClassLibrary1 => Class Library (Package)
BookStore.ClassLibrary2 => Class Library
BookStore.Web => MVC5
In BookStore.Web, I can reference BookStore.ClassLibrary2, but fail to reference BookStore.ClassLibrary1.
It shows an error "A reference to 'ClassLibrary1' could not be added."
My question is how to reference a Class Library (Package) in VS2015? Thank you so much!
Looks like your ClassLibrary1 project is a Class Library Package, not a class library project. Class Library Package is used to create Nuget packages that can target any platform.
There are a number of benefits of ASP.NET 5 Class Library projects (.kproj) over Class Library projects (.csproj):
ASP.NET 5 class libraries easily support cross-compiling projects to multiple targets, such as aspnet50, aspnetcore50, net45, and various other portable class library variations. This includes rich Visual Studio support for Intellisense to notify you which APIs are available for which targets.
NuGet packages are automatically created, which is an extremely common thing to do with class libraries.
Better productivity when it comes to things like automatically refreshing Solution Explorer when the file system changes. Fewer conflicts in source control when trying to merge conflicting changes in the *.csproj file.
Can be compiled cross-platform (in part because it doesn't depend on MSBuild)
You can reference a *.csproj project from a *.kproj project (this was just made a lot easier with the new preview of Visual Studio 2015), but it was always possible with some manual steps.
Why does the name have "ASP.NET" in it?
As far as the names goes, it's a relic of history that will soon be addressed. The new project type is useful far beyond ASP.NET 5 applications. Expect to see new names in a future preview of Visual Studio:
.NET Console Application (Cross-platform)
.NET Class Library (Cross-platform)
With the release of Visual Studio 2015 RC you can see the updated project template names:
Class Library (Package)
Console Application (Package)
These use the project.json file and the .NET Execution Environment (DNX) to build, run, and package (into a NuGet package) the project.
These project templates continue to show up in the New Project dialog under the "Web" node, but now also show up in the main "Visual C#" node as well.
Here is a good link as you need to referance a dll that the new clas library does not build. https://evolpin.wordpress.com/2015/01/25/vnext-and-class-libraries/
Either use a plain old class library or use a Nuget class library, publish it to a local or public Nuget repo and add it to the web project from there.
I doubt about dependency of ClassLibrary1 and I can even see that in your screenshot,
It seems ClassLibrary1 is looking for some dependent dlls, so you might need to add those dll first then you can go ahead and add it.
Something similar happens here too
More details about Depencies can gather from this MSDN link you can directly jump to Dependencies node for Bower and NPM dependencies
All:
I need advise on how to use Nuget to make my project dependencies (libraries) available to other developers who will in turn have my project as dependency. See scenario below for details:
I have created a Visual Studio 2013 project (ProjA) in a solution (SolA) which has a dependency on a Library (LibA [which I do not commit into source control]). I have used Nuget to manage/fetch the dependencies of project ProjA (i.e. library LibA) via Nuget.Config in .nuget folder at solution SolA level and everything is working ok. Developers are able to checkout solution SolA and build/deploy with Nuget fetching LibA from a local server.
My issue is that I now need to have developers build their project (ProjB) in another solution (SolB) but which will import/use ProjA as a dependent project. Issue is that I cannot find a way to make Nuget fetch the dependencies of ProjA (i.e. LibA) when built as part of solution SolB. I tried putting the Nuget.Config File in the level of ProjA, but VS build seems to ignore it.
Any ideas????
You seem to be mixing two different but not-very-compatible approaches to code sharing here:
Code-level dependencies
Package-level dependencies
Code-level dependencies between different solutions are generally A Bad Thing, and you should avoid them. A solution should encapsulate and build all the source code it needs to, relying on 'library' DLLs (whether provided as raw DLLs or via NuGet).
I recommend that you re-work your solutions using the 'Package-level dependency' pattern, so that you have a separate 'library' solution which provides a NuGet package (or set of NuGet packages) which the other two solutions can consume:
Here is the current (awkward) dependency graph:
Solution A Solution B
Proj A -----------> Proj B
^--------------------'
Here is what I propose with the separate library solution:
+----> Solution L <----+
| |
Solution A Solution B
Solution A and Solution B thus consume the NuGet packages produced by Solution L (the library project). This is the dependency relationship which probably underlies your code anyhow, based on what you describe.