Example:
Nuget package A is a set of code snippets (it does not contain an assembly).
Nuget package B is a normal assembly and it is using package A - just for internal means.
Question: What can I do, to avoid, that package A is also installed, when somone installes package B?
Found something in documentation of nuget:
Starting from version 2.7, the pack command will ignore entries in the packages.config file which have an attribute developmentDependency set to true and will not include that package as a dependency in the created package. For example, consider the following packages.config file in the source project
That seems to solve the problem.
Related
I used NuGet Package Explorer (for the first time) to create a .nupkg to share with others. I have one DLL that targets NetStandardLibrary 2.0,
But when I try to add the package I receive the following error:
Could not install package 'iCANMVCSDK 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I thought that by using NETStandard 2.0 it could be installed in any .NET app. I also tried adding additional assemblies:
I rebuild, repackage, and I still get the same error. What am I missing?
I tried editing the project file like this:
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
When I try to build after adding net472, I receive the following error:
The type or namespace name 'Http' does not exist in the namespace 'System.Net'
What really makes no sense to me is that I can add the DLL directly into the project (the one that targes NET 4.72) and it works as expected. The problem is when attempting to install it as a NuGet package.
I developed a nuget package "nuget_X" installed on a project "project_1".
I have a second project "project_2" that reference "project_1".
If "project_1" is published as nuget package "nuget_1", I can force "project_2" to reference "nuget_X" by declaring "nuget_X" as dependency of "nuget_1"
But "project_1" is referenced as "ProjectReference". So, how can I configure "nuget_X" or "project_1" to force "project_2" to install "nuget_X"?
PackageReference on Visual Studio 2017 don't allow to force nuget of dependency to be installed when using ProjectReference. But it allow to produce an acceptable equivalent result. for more details, see comments.
When building a nuget package with folder lib\i-made-this-up\, nuget Pack will output the following message:
The folder 'i-made-this-up' under 'lib' is not recognized
as a valid framework name or a supported culture identifier.
Folder lib\net40-wpf\ does not output this message so apparently it is a valid framework name. My questions is: how is net40-wpf defined? I expected it to be on this page but it isn't:
https://docs.nuget.org/create/enforced-package-conventions
Do I miss something? Or is there a better source of documentation?
You have the main documentation link for the NuGet target frameworks:
https://docs.nuget.org/create/enforced-package-conventions
Unfortunately it is out of date and is missing newer target frameworks that NuGet supports.
A few more target frameworks are mentioned in the following blog post:
http://blog.nuget.org/20150729/Introducing-nuget-uwp.html
Currently the best place is the NuGet source code. For NuGet v2 the known target frameworks are defined in the VersionUtility class:
https://github.com/NuGet/NuGet2/blob/2.8.6/src/Core/Utility/VersionUtility.cs
For NuGet 3 the list of target frameworks is defined in the FrameworkConstants class:
https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Frameworks/FrameworkConstants.cs
NuGet 3 also has a set of runtime identifiers which are defined in a NuGet package so it is extensible.
I've imported the Hangfire Source code from Github into my existing VS 2013 solution. When I attempted to build all projects within my solution, I get several errors:
Error 6 The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Jerry_Dev\Documents\GitHub\Hangfire\src\Hangfire.SqlServer\SqlServerDistributedLock.cs 20 7 Hangfire.SqlServer
In Package Manager, when I do: "Install-Package Dapper", it says
'Dapper 1.38' already installed.
Hangfire.SqlServer already has a reference to 'Dapper 1.38'.
I see Dapper dot net installed in my Manage Nuget Packages Window in my Hangfire.SqlServer project
We don't store the packages folder under source control to reduce the source code size. Hangfire uses Automatic Package Restore in Visual Studio instead of obsolete MSBuild-integrated package restore. The Automatic Restore downloads missing packages automatically on each build, but it works only with NuGet ≥ 2.7, so you have the following options:
Update NuGet to the latest version
Please see the official docs.
Run the build script
Go to the root Hangfire directory and run the build.bat file. It will automatically restore all the missing packages.
I am currently trying to publish a load of nuget packages for all the projects in this solution. The projects are setup in a simple tree, with Myre being the base project and everything depending on it:
Myre <- Myre.Debugging <- Myre.Debugging.UI <- Myre.UI
Myre <- Myre.UI
Myre <- Myre.Entities <- Myre.Graphics
I'm trying to package up each separate project as a nuget package with the correct dependencies on the other Myre subproject packages as necessary.
My first step was to make a package for Myre (nuspec and bat file of process). This seems to work nicely, the gallery shows Myre as having a ninject (another nuget package) dependency and all is well.
The problem comes when I tried to make the next package. Myre.Debugging depends upon Myre (with a normal project reference) and nothing else. Using this nuspec with nuget pack (verbose) gives:
Attempting to build package from '(x86) Myre.Debugging.csproj'.
Packing files from 'C:\Long_Path\Myre\Myre.Debugging\bin\x86\Release'.
Add file 'C:\Long_Path\Myre\Myre.Debugging\bin\x86\Release\Myre.Debugging.dll' to package as 'lib\net40-Client\Myre.Debugging.dll'
Add file 'C:\Long_Path\Myre\Myre\bin\x86\Release\Myre.dll' to package as 'lib\net40-Client\Myre.dll'
Add file 'C:\Long_Path\Myre\Myre\bin\x86\Release\Myre.XML' to package as 'lib\net40-Client\Myre.XML'
Found packages.config. Using packages listed as dependencies
Id: Myre.Debugging
Version: 1.0.0.2
Authors: Microsoft
Description: Description
Dependencies: Ninject (= 3.0.1.10)
Added file 'lib\net40-Client\Myre.Debugging.dll'.
Added file 'lib\net40-Client\Myre.dll'.
Added file 'lib\net40-Client\Myre.XML'.
Successfully created package 'C:\Long_Path\Myre\Myre.Debugging\Myre.Debugging.1.0.0.2.nupkg'.
As you can see it picks up a packages.config file (presumably from Myre since there isn't one here) which it then determines a Ninject dependency from. If I wanted Myre.Debugging and Myre to be a single package that would be fine. However this is not what I want, I want Myre.Debugging to pick up a dependency on the Myre package.
How can I setup nuget to use Myre as a package reference and not simply to copy the Myre assemblies into the Myre.Debugging package?
Edit:: I tried not using -IncludeReferencedProjects and specifying:
<dependencies>
<dependency id="Myre" version="1.0.0.1" />
</dependencies>
But for some reason this just creates a package with no dependencies at all! Even if manually specifying dependencies like this did work, it's hardly ideal.
According to the NuGet command line reference for the Pack command, the IncludeReferencedProjects switch works as follows:
Include referenced projects either as dependencies or as part of the package. If a referenced project has a corresponding nuspec file that has the same name as the project, then that referenced project is added as a dependency. Otherwise, the referenced project is added as part of the package.
In your case, Myre.Debugging.nuspec does not match the project file names: (x86) Myre.Debugging.csproj, etc. I suspect that you'll need to match up those file names to get that command line option to work.
Alternatively, if you want to get this to work with a <dependencies> element in your nuspec file, you may be facing another variant on the name mismatch problem. Your Myre.nuspec file defines its ID as follows:
<id>$id$</id>
The NuSpec reference says that the $id$ token is replaced by "The Assembly name." If it's talking about the name of the DLL (ignoring the extension), then I think the generated IDs will be (x86) Myre, etc. You might want to try hard-coding the ID temporarily just to see if that resolves the issue.
I haven't tried making these suggested changes, and I can't guarantee they will work, but I hope this points you in the right direction. Good luck!