Explicitly set the order of build targets defined in NuGet packages - visual-studio-2017

I have a Visual Studio 2017 project for building an Azure Function App. This project contains (amongst others) two NuGet packages - Microsoft.NET.Sdk.Functions and OctoPack. The packages are referenced in this order by the .csproj file for the Project in question.
The Microsoft.NET.Sdk.Functions package contains the target _GenerateFunctionsPostBuild -
<Target Name="_GenerateFunctionsPostBuild" AfterTargets="Build">...</Target>
The OctoPack package contains the target Octopack -
<Target Name="OctoPack" Condition="$(RunOctoPack)">...</Target>
When building, it's essential that the _GenerateFunctionsPostBuild target runs before the OctoPack target, otherwise required files are not available in the NuGet package generated by OctoPack.
As I can't edit the NuGet packages directly, I'm unable to explicitly state AfterTarget="_GenerateFunctionsPostBuild" for the OctoPack target. Is there any way I can force the targets to run in the order that I require?

In lieu of a answer, I've come up with a workaround. Instead of using OctoPack, I'm manually generating the NuGet package after the build has completed.
In the NuSpec file, I've added a couple of tokens for %Configuration% and %Version% so that I can choose the files to package based on the configuration, and obviously customise the version.
Here's what I'm doing - obviously I'm making $version before these lines.
$dir = (Get-Location).Path
& D:\nuget\4.4.1\nuget.exe pack $dir\AzureFunction\AzureFunction.nuspec -BasePath $dir\AzureFunction -Properties "Configuration=Release;Version=$version"

Related

How do I create nuget package and update metadata for C++/CLI vcxproj project

I have created C++/CLI project to wrap native library. How can I create nuget package using powershell command to add this wrapper library as well as native C++ dll it wraps.
I can see some posts for how to use nuget packages in C++/CLI projects but cannot find anything useful for actually creating nuget package for C++/CLI project itself. Nuget.exe "pack" command fails for .vcxproj project.
The NuGet.exe will automatically replace metadata like id, version etc from assembly/csproj file but we are not using vcxproj to build nuget package for C++ CLI project.
I solved the problem by using nuspec file directly while building the library from bamboo itself. I used bamboo to set the build version of the metadata. All other metadata is hardcoded in the nuspec file which does not need to change with every build.
& "NuGet.exe" pack "Library.nuspec" -Version ${bamboo.BuildVersion} -OutputDirectory ${bamboo.build.working.directory}

Nuget "Manage Packages" dialog. Project names are mixed up

I've got a Visual Studio 2017 solution with several C# class library projects. On disk they take this structure:
MyProduct
MyCompany
MyCompany.ModuleA
MyCompany.ModuleB
MyCompany.ModuleC
But when I look at them in the "Manage NuGet Packages for Solution, the checkboxes show up in the dialog inconsistently. ModuleC appears strangely. Like this:
MyCompany.ModuleA
MyCompany.ModuleB
MyProduct\MyCompany\MyCompany.ModuleC
Also, whenever I build Module C, it keeps creating the following 3 files in its output /obj folder
- MyCompany.ModuleC.csproj.nuget.g.props
- MyCompany.ModuleC.csproj.nuget.g.targets
- project.assets.json
Neither of the other two modules does this.
I'm trying to understand the reason for the inconsistency and to fix it if I can. I have tried combing through the text of the .csproj files for these various projects but I can't spot any differences that might make this happen. And the raw text of the .SLN file project entry all look consistent for each of the 3 modules.
How does NuGet decide what name to put in the Manage Packages for Solution dialog?
Why is NuGet creating those temporary files in the output folder for Module C but not Module's A or B?
How does NuGet decide what name to put in the Manage Packages for Solution dialog?
It is depends on the NuGet manager type, packages.config or PackageReference.
If the project use packages.config, project name will be put in the Manage Packages for Solution dialog. If the project use PackageReference, project file name and relative path will be put in it. That because NuGet will update the project file .csproj when we install the nuget package with PackageReference. So, in the the Manage Packages for Solution dialog, it shows the relative path+project file name, like ClassLibrary1\ClassLibrary1.csproj.
Why is NuGet creating those temporary files in the output folder for
Module C but not Module's A or B?
That because NuGet with PackageReference controls the msbuild items that are generated for these files into the obj\projectname.csproj.nuget.g.props, obj\projectname.csproj.nuget.g.targets and project.assets.json file.
You can unload your project, check if the project file MyCompany.ModuleCuse the PackageReference, like:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>11.0.2</Version>
</PackageReference>
</ItemGroup>
For some more details, please check this official blog: NuGet is now fully integrated into MSBuild.

MSBuild to apply a nuget package to a project at build time

I have a cmake project that builds fine on Linux and that I want to build also on Windows. The code is portable and is made of C++ so... it should build. The only thing is that, on Windows, I need to use nuget to restore some packages, cpprestsdk is one of them. Now when I run
cmake .
CMake will generate solution files and projects files that I don't want to include in my VCS at all. The thing I want MSBuild to do is to apply the packages contained in my packages.config to all the project files found in the project directory.
Anyone knows how?
The thing I want MSBuild to do is to apply the packages contained in my packages.config to all the project files found in the project directory. Anyone knows how?
I am afraid you can not do such things. That because whether you are using MSBuild or NuGet to do this thing, you have to use to the nuget.exe to do it. However, install nuget packages to the project file relies on VS capabilities not nuget.exe and nuget team not plan to bring it to the exe.
The NuGet Command Line does not actually install any packages. The install command is actually doing a restore operation.
This means that nuget.exe install will only download and extract the package into the output location. It will not modify the project file. Although, the package manager console seem to offer "Install-Package" for doing this, but you have to open each project files with Visual Studio and execute Install-Package in the package manager console for each project files, which is not what you want. So you could not enable this script outside of visual studio.
So we could not use MSBuild to apply the packages contained in the packages.config to all the project files found in the project directory.
You can refer to this thread and this thread for details.
Hope this helps.

Nuget Package Installs Via Console But No Reference Added For C++ Project

I am trying to install the NuGet package detailed on this webpage: https://learn.microsoft.com/en-us/azure/storage/storage-c-plus-plus-how-to-use-blobs
For reference, the instructions are:
Windows: In Visual Studio, click Tools > NuGet Package Manager > Package Manager Console. Type the following command into the NuGet Package Manager console and press ENTER.
This works... kind of. The package is downloaded locally, but the reference isn't being added to my project. When I install the package manually or from the PM Console, no reference is added.
Instructions I've been able to find (such as here) just insist that the references will be automagically added. Which is great when it works, but it provides no debug reference point or how to add them manually.
Are there other options I'm missing?
Thanks.
the reference isn't being added to my project. When I install the package manually or from the PM Console, no reference is added
That is because NuGet cannot directly add references to native projects, the ‘native’ target framework is not recognized within the \lib folder.
For the detail information, you can refer to the Support for Native Projects.
Besides, after installed the wastorage package, you will notice that the blob.h and storage_account.h were added to External Dependencies:
Then you can add the following include statements to the top of the C++ file successfully where you want to use the Azure storage APIs to access blobs:
#include <was/storage_account.h>
#include <was/blob.h>
Update:
According to the JuniorIncanter comment, add the .targets, and .props file in the .vcxproj:
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\cpprestsdk.v120.windesktop.msvcstl.dyn.rt-dyn.2.9.1\build\native\cpprestsdk.v120.windesktop.msvcstl.dyn.rt-dyn.targets" Condition="Exists('..\packages\cpprestsdk.v120.windesktop.msvcstl.dyn.rt-dyn.2.9.1\build\native\cpprestsdk.v120.windesktop.msvcstl.dyn.rt-dyn.targets')" />
<Import Project="..\packages\cpprestsdk.v140.windesktop.msvcstl.dyn.rt-dyn.2.9.1\build\native\cpprestsdk.v140.windesktop.msvcstl.dyn.rt-dyn.targets" Condition="Exists('..\packages\cpprestsdk.v140.windesktop.msvcstl.dyn.rt-dyn.2.9.1\build\native\cpprestsdk.v140.windesktop.msvcstl.dyn.rt-dyn.targets')" />
<Import Project="..\packages\wastorage.v120.3.0.0\build\native\wastorage.v120.targets" Condition="Exists('..\packages\wastorage.v120.3.0.0\build\native\wastorage.v120.targets')" />
<Import Project="..\packages\wastorage.v140.3.0.0\build\native\wastorage.v140.targets" Condition="Exists('..\packages\wastorage.v140.3.0.0\build\native\wastorage.v140.targets')" />
For those that stumble onto the question, there is no working solution. The issue arose because I was creating a UAP app, and the given Nuget package does not have UAP support. At that point, in order to continue I must download the source code for the Nuget package and recompile it with the -ZW flag.
See here: https://msdn.microsoft.com/en-us/library/mt186162.aspx
If you have source code for the DLL or static library, you can recompile with /ZW as a UWP project.

Where are nuget package manager include directories set in VS 2015?

i am currently trying my first steps with nuget package manager (3.4.3.855) in VS 2015 (Enterprise). For my C++/Qt project i managed to find some libraries i need and they seem to be correctly downloaded to <myprojectDir>/packages/<package_name>/... folders.
However, it is a mystery to me, where and how include folders for headers and/or libs are specified for the project?
I mean, for example with the Eigen library, after importing the nuget package i can just #include <Eigen/core>, which is located in
<myprojectDir>\packages\Eigen.3.2.9\build\native\include
and everything works fine, but i neither have the packages\Eigen.3.2.9\build\native\include-path popping up in the VC++ Directories->Include Directories list in the property pages nor is there a custom property page in the project properties (yes, i did not click the solution properties ;) ) as seen e.g. in this example video with the zlib package. I do not even have this property page if I install the zlib package.
While it seems to work somehow under the hood for Eigen, it does not for the Visual Leak Detector (vld) package... so knowing how things work would be great ;)
Thanks for any help...
From NuGet 2.5, C++ project recognizes the installed packages through MSBuild properties and targets files from NuGet package. After installing packages in C++ project, the MSBuild files are imported into your project file. So the projects will know how to find and use the contents of the NuGet Packages.
To make MSBuild integration better, NuGet has created a new convention for automatically importing MSBuild properties and targets from a NuGet package. Alongside the existing \content, \lib, and \tools folders, NuGet now recognizes a new top-level folder: \build. You could open the Eigen package that you have installed through NuGet Package Explorer, there has a \build folder and a Eigen.targets file which contains MSBuild properties.
Please refer to the MSBuild Integration part from below link:
http://blog.nuget.org/20130426/native-support.html