Create package that references another package in solution - nuget-package

I often have this situation:
Foo.sln
Foo.csproj
Foo.Wpf.csproj
Then I create:
A nuget package Foo.nupkg
A package for Foo.Wpf.nupkg referencing Foo.nupkg.
I could not find out how to specify that dependency in the docs.

Just create a paket.template for each project and make sure you set the "type" property to "project". Paket will figure things out automatically for you
Edit:
Sample:
Foo.sln
Foo.csproj
paket.template
Foo.Wpf.csproj
paket.template
Where the paket.template files looks like this:
type project
// This assumes that Author and Version are specified in the project.
If you want to override the defaults check out the docs

Related

NuGet - choose references to add on install

I want to pack/publish a NuGet package. (private) using a .nuspec file :
\build
\netstandard1.4
\MyProject.dll
\MyProject.Unmanaged.dll
\net462
\MyProject.dll
\MyProject.Unmanaged.dll
In this package, I have a dll that I want to reference in my project, and another that I can't reference, but that is still required.
When I add the package to a project, the dll are automatically referenced, so I get an error : "Failed to add reference to 'MyProject.Unmanaged'.
Please make sure that the file is accessible, and that it is a valid assembly or COM component.
Is there a way to choose which dll must be automatically referenced or not ?
See the chapter "Explicit assembly references" : https://learn.microsoft.com/en-us/nuget/schema/nuspec

Provided dependency from project (Gradle)

How can we declare a dependency as provided from another module? i.e. something like:
dependencies {
compile 'javax.persistence:persistence-api:1.0'
provided 'com.google.code.gson:gson:2.5'
}
but instead of pulling dependency from a repo, I want to include a project in another project. I would expect something like this to work:
dependency {
compile 'javax.persistence:persistence-api:1.0'
provided project(':mymodule')
}
Gradle does not have a built in provided scope/configuration. You can define your own provided configuration. See here: https://stackoverflow.com/a/34899917/745574
But in your case, you do not really need it. As long as mymodule is already in settings.gradle, just include your module as:
compile project(':mymodule')

NuGet Package Questions (Asked by a NuGet *Newbie*)

I have a couple of NuGet package questions that I cannot seem to locate an answer for.
First, most packages have one or more dependencies on other packages. These dependencies are listed with a minimum (and sometimes, maximum) version number. What is an easy way to determine this range when creating packages? For example, my code depends on a particular package. If I install the earliest version, my code will not compile. If I install the latest version, my code will compile. Somewhere along the line (between the oldest and newest version), the code I need to reference was added. How do I determine where (read, what version) this was added in a particular package so I can set the minimum version?
Second, when I set a package dependency, is it an all or nothing type of thing? By that, I might need only an assembly or two from a package but not the rest. Is there any way to get rid of the extra stuff? As an example, the package I use has an indirect dependency on Newtownsoft.Json. However, my code does not use this assembly in any way. Should I just ignore this? I don't want extra assemblies that are not required floating around.
For your second question, package dependency supposed to be essential for the dll to compile, so its strange that some of the dlls are unnecessary. But if indeed its the case, there is no way to avoid it, in the package install process, because the NuGet recognize all the dll files under the lib folder in the nuget package, and add them as reference.
But you can delete the reference from the project config file (.csproj), and in the package restore process, nuget only download and extract the nuget package. and dont touch the .csproj files.
I didn`t understand exactly your first question, but you can enforce the nuget package version specific for your needs, link: http://docs.nuget.org/docs/reference/versioning

How to reference without copying a library project on Android Studio?

Yes, everywhere I can learn how to make a module from a project that will copy the library project. But that's no good, since a change in the library project would have to be replicated on every project that uses it. So, how can I reference it from a folder that's outside the project in a dynamic way?
Got it:
In your project, go in settings.gradle and declare something like this:
include ':LibReferenceName'
project(':LibReferenceName').projectDir = new File(settingsDir, '../relativePath/toThe/libraryModule/fromTheProject')
And at the modules that requires the library, include something like this in the build.gradle of it:
compile project(path: ':LibReferenceName')
You can also not use settingsDir and just put the absolute path of the project.

Some dll from nuget packages are not copied to /bin

I know that this is a question that has been discussed before but I have a situation that I don't understand.
I have the following projects
Project A
Project B
NuGet Package "log4net"
NuGet Package "ServerAppFabric.Client"
Project A has a visual studio reference to Project B. I'm using both packages in code in Project B and I am building in debug mode. Project B config looks like this.
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.0\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationServer.Caching.Client">
<HintPath>..\packages\ServerAppFabric.Client.1.1.2106\lib\Microsoft.ApplicationServer.Caching.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationServer.Caching.Core">
<HintPath>..\packages\ServerAppFabric.Client.1.1.2106\lib\Microsoft.ApplicationServer.Caching.Core.dll</HintPath>
</Reference>
*Why is only the dll-file from log4net copied into the bin folder of Project A and not the Client and Core files? Any help or explanation is appreciated! *
I had the same problem with a somehow complex dependency graph.
Go to the Reference Properties and set Copy Local=True.
Compile and check if the assembly was copied to the bin folder.
If that doesn’t fix your issue try this answer: https://stackoverflow.com/a/19889803/1074245
In order to answer your question precisely, we'd need to know a couple of things.
One explanation depends on what references you have in Project A. For example, it could be that project A, other than referencing project B, also includes additional references, among which there are Microsoft.ApplicationServer.Caching.Client and Microsoft.ApplicationServer.Caching.Core, maybe with the option Copy local set to false - but not log4net. In this case, the copy of the former two will happen only for Project B.
Another possible explanation depends on what your code does with the references in project A and project B. The MSBuild process does not automatically copy assemblies of references that are not actually used in a project.
Finally, in case you are relying on Build Events to copy references, have a look at the Output panel to make sure that there are no errors despite a successful compilation.
In any case, in order to make sure that all NuGet packages are copied, I find it useful to edit the .csproj file and, among the <PropertyGroup> tag, add this:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
From the documentation:
If you set this CopyLocalLockFileAssemblies to true, any NuGet package dependencies are copied to the output directory. That means you can use the output of dotnet build to run your plugin on any machine.
I don't think this is related to NuGet. It should be related to how references work in Visual Studio or MSBuild. If you just reference a library in ProjectB, it won't show up in ProjectA's bin folder. However, when you use some type from the referenced library,only then it will show up in bin folder.

Resources