I have a number of helper libraries that I would like to turn into a single NuGet package:
ProjectA
ProjectB (references ProjectA)
ProjectC
I can make individual packages of these:
nuget pack ProjectA.nuspec
nuget pack ProjectB.nuspec
nuget pack ProjectC.nuspec
Or I can "bundles" of referencing projects:
nuget pack ProjectB.nuspec -IncludeReferencedProjects
nuget pack ProjectC.nuspec
But I'd very much like a single .nupkg file containing all the projects.
Is this possiblie to achieve?
-S
I ended up creating a "bundling project" that only references the other projects:
ProjectA
ProjectB (references ProjectA)
ProjectC
ProjectD (references ProjectA, ProjectB and ProjectC)
With this in place, I can pack everything into a single NuGet package.
nuget pack ProjectD.nuspec -IncludeReferencedProjects
Not super elegant to achieve, but it kind of makes sense to have a neutral project without its own functionality to bundle up the other diverse projects.
Related
I try to build and install nuget pack with c# proxy for c++ dll.
So, when I install my pack to target project with Visual Studio 2019, it seems, that install is success. But I not see my c++ dll copied from nuget content to in project folder.
My first version of nuget pack used build/Install.ps1, and it copied success my c++ dll to target project folder, but.. not for all projects. For example, when in VS2019 Nuget Package Manager I checked mark for target project with name like ProjectName - all is OK, Install.ps1 execute. But sometime projects in Nuget Package Manager have names like ProjectName\ProjectName.csproj - unfortunately, Install.ps1 not executed for such projects. This why I should to return to use targets files for copying.
Ok, I created target file, pack my nuget packet and install it with VS2019 Nuget Package Manager. C++ dll not copied, but, repeat, packet was installed success. This is content of installed packed in solution package dir:
- Comp.Dep.NetClient.2.3.1
- build
- netstandard2.0
- Comp.Dep.NetClient.targets
- Comp.Dep.NetClient.props
- c++.dll (need to be copy to target project folder)
- lib
- netstandard2.0
- c#.dll (client proxy, added to project references)
- Comp.Dep.NetClient.2.3.1.nupkg
I tried many kinds of Comp.Dep.NetClient.targets content. I try to use Comp.Dep.NetClient.props instaed. Nothing help :) dll not copied. Now, my Comp.Dep.NetClient.targets and Comp.Dep.NetClient.props has next content:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
<None Include="#(NativeLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
I used different kinds from this
https://qastack.ru/programming/19478775/add-native-files-from-nuget-package-to-project-output-directory
..and from this
How can I set the 'copy to output directory' property in my nuspec file?
..and others :) nothing work..
For example, my target project structure after install pack is next:
Solution dir
packages
Comp.Dep.NetClient.2.3.1
..(see structure on previous example)
MyApp.sln
MyApp (project dir)
MyApp.csproj
...other files, but not c++ dll
I expect that after install my nuget to MyApp project is success, my c++ dll will be copied to MyApp (project dir). But it not happens.
Why??!!
I have projectA and projectB in the same solution.
projectA creates its own package, but I override the package id by using a prefix:
<PackageIdPrefix></PackageIdPrefix>
<PackageId>$(PackageIdPrefix)$(MSBuildProjectName)</PackageId>
The command to generate the package is :
dotnet pack .\$(ProjectName).csproj --include-symbols --no-build -o C:\dev\UPP\Packages -p:PackageIdPrefix=MyPrefix."
Therefore the generated package name is MyPrefix.ProjectA.nupkg
projectB references projectA as a project reference since they belong to the same solution.
projectB creates its own package, in the same way:
<PackageIdPrefix></PackageIdPrefix>
<PackageId>$(PackageIdPrefix)$(MSBuildProjectName)</PackageId>
However in the nuspec of the generated MyPrefix.ProjectB.nupkg I end with :
<dependency id="ProjectA" version="1.0.0" exclude="Build,Analyzers" />
So the prefix was not used to create the dependency in the nuspec. Obviously this leads to an error when I try to install this package since the dependency ProjectA does not exist...
How can I prefix the dependency ?
I have to tag every .dll with it's version from assembly,
so from Service.dll it becomes: Service-v1.0.0.21455.dll
I tried this two approaches, but each has flows:
Build > Rename > Pack with nuget pack Service.csproj
The challenge is that after I do so, Nuget can't find missing Service.dll
Of course, because it's bin/Release/Service-v1.0.0.21455.dll
Build > Rename > Pack with nuget pack .nuspec
Issue I'm facing here is that dependencies are missing withing the nuget package
This is brief explanation, let me know if it's 'even possible'/'make sense'/'you need more details'
I have a solution that looks like this:
-> Proj A
-> proj B
Proj B references Proj A
Both projects have a paket.template that looks like this:
When I paket pack, I get two nugets created, one for each project. Fantastic.
However, I now want to make ProjA.dll be bundled inside ProjB's nuget (ProjB is an .exe/tool that needs its dependencies bundled to operate).
Adding include-referenced-projects true to ProjBs paket.template has no effect, neither does any combination of paket command line --include-referenced-projects true that I've tried.
Is this supported? Is this a bug?
Either way, how can I achieve what I want, without making separate solutions to house ProjA and ProjB?
If you look at ProjB.nuspec from resulting nuget package you see nuget reference to ProjA package. So resulting ProjB package has all needed dependencies.
You can achive what you want by several ways:
Pack ProjB by command paket pack <output> --template <path to ProjB paket.tempplate> (without --include-referenced-projects flag). Pack ProjA by separate command if you need it.
Delete paket.template from ProjA, then pack ProjB with --include-referenced-projects flag. But in this case package for ProjA will not be created.
Change paket.template type for ProjB from "project" to "file" and specify all dependencies and files manually.
(HACK:)) you can rename paket.template for ProjA from paket.template to <somethingElse>.template and pack ProjB with --include-referenced-projects flag.
Paket will not find than ProjA produce nuget package and add it as binary dependency to ProjB. You still can pack ProjA with separate command paket pack --template "path to <somethingElse>.template"
I have two projects
A.csproj
B.csproj
where B references A (reference to project in solution)
I want to automate creation of packages, where package B will contain dependecy to package A
I've generated nuspec using nuget spec A.csproj and created package using nuget pack A.csproj. The same for project B.
however B.nuspec does not contain dependecy to nuget package A?
I want to automate creation of nuget packages on TFS build server, where assembly version is determined at build time.
In package B, how to add dependency to package A with correct version?
Firstly, to add the referenced projects as part of the package, you need to use the IncludeReferencedProjects option.
The command line is something like "nuget pack A.csproj -IncludeReferencedProjects"
Secondly, as you want to create NuGet packages during TFS build process, you need to create one PowerShell script which is similar to the followings, and include the PowerShell script in the Pre-build script (Assume you're using TFS2013 or TFS2015).
$projectFile = "project.csproj"
$nugetPath = “NuGet.exe"
$version = $Env:TF_BUILD_BUILDNUMBER
Write-Host ("packing $projectFile...")
& $nugetPath pack "$projectFile" -Version $version -Symbols -IncludeReferencedProjects