Set Nuget Package Version from Project Info - build

My setup is rather simple: MyGet pulls my repo from GitHub on commit and builds. I then manually push the successfully built project to NuGet.
The version is manually set except for the build counter. Is there a way to pull the version from the AssemblyInfo, .csproj file or somewhere else?
I've read the docs and the only thing I can find is using GitVersion and a build file. I'm hoping there's a cleaner/simpler way, e.g. %project_version% :)

By definition, a build counter is managed by the build system and can only be reset at best.
To use the version from AssemblyInfo.cs as the NuGet package version, you could create a .nuspec manifest next to your .csproj file (give it the same file name only differing by extension), and use the $version$ placeholder.
I've got a blog post that explains this in further detail: https://www.xavierdecoster.com/post/2012/04/26/nuget-version-token-explained.html

Related

How to clean including nuget packages

If I want to keep backups of my code and I don't want all the libraries and nuget libraries in the backup, how do I do that?
I run clean on my solution and I noticed there are still DLL's and EXE in the bin and obj folders. Ok, I can delete those folders manually. I can delete the package folder which will remove all the nuget libraries, but if I ever want to restore, will my solution redownload all the nuget packages needed for the project? I'm afraid to test that theory and from what I read there is meta data and other things in the package folder will will cause me problems. If I zip what I have after deleting bin and obj folder, the zip is 450MB. If I go into the zip and delete the package folder, I see it is only 25MB. It seems to be all in the Package folder. From an ReactJS perspective, I can do a build and it cleans all this out and when I want to reimport for an existing project, I run a install. Is there not something like this for Visual Studio 2017? Will I be able to recover easily if I just delete the package folder before I back it up?
If I want to keep backups of my code and I don't want all the
libraries and nuget libraries in the backup, how do I do that?
Which way do you backup the code? According to your description, it seems you're trying to zip the solution and store it somewhere to do the backup. If so, you can delete the bin, obj and packages folders before you zip the solution. (You can even delete the .vs folder)
Is there not something like this for Visual Studio 2017? Will I be
able to recover easily if I just delete the package folder before I
back it up?
There're two ways to manage nuget packages in VS, packages.config and PackageReference format. Since you have packages folder in your solution, I think you use packages.config format. The info about nuget packages your project consume are defined in packages.config and xx.csproj file. After you delete the packages folder, you can easily recover the packages with the help of the packages.config file and xx.csproj file.
Import the solution which you've deleted bin, obj, packages folders in VS, right-click the solution in Solution Explorer and choose Restore nuget packages option, then it will help install the packages your solution need according to your packages.config file. So the answer is Yes for Will I be able to recover easily.
In addition:
1.When you install one nuget package, it will firstly install it in global-packages folder, and then copy them to your solution. So in same machine, if you zip the solution before delete the packages folder in solution. When you recover, it will first look for the cache, if the cache doesn't have the required nuget packages, it will install them from package source.(like nuget.org). You need to enable these two options in VS setting.
2.If you're using PackageReference format, the packages are stored in %userprofile%\.nuget\packages but not in your solution. And you can easily recover the packages though you zip the solution and copy it to remote server.
3.Apart from the restore nuget packages option in VS, you can also use command-line like nuget.exe, msbuild.exe... More details see here.
Why not just use some source control to do just that?
If you use Team Foundation Server with TFVC or Git it will do just that. You will have all your code under version control, without dll´s, bins, build artifacts, packages or anything. Without all those heavy, innecesary things that can be recreated by just rebuilding the solution again.
And of course you will enjoy all the advantages of having your code under source control: namely, not only having a backup of your code, but of all changes it has undergone with thus far.
Just saying.

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}

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.

VS2017 Installer project output does not replace the current installation

I have a standard windows forms application that is being deployed using the VS2017 setup project. When opening the setup project using the "File System", I added to the application folder the following:
Primary output from the win forms app.
The EPPlus library's dll.
Some excel files.
The setup project gives the output .msi package just fine. The problem is, when I run the .msi output after building the setup project (of course after building the source project) and run the application, I do not see my updates, even the files on C:\Program Files .... directory are not modified. I tried changing the product code and the increasing the version and it does not work. My questions are:
Besides removing and installing the program again, is there anyway to make the installer package actually updating the software's installation?
How to avoid the problem in #1 no matter how much I update the software?
What is the cause and how to avoid this error "Another version of this product is already installed"? I'm not sure of what I did for it to pop up.
If I want some part of the source code to be in a separate dll, is it as simple as adding a class library project and adding its output to the setup project?
Thank you very much.
The way you do the upgrade is to use the RemovePreviousVersions project setting. The steps are:
Increment the setup project's version and accept the changes, this will include a change of ProductCode.
Make sure that RemovePreviousVersions is set true.
The UpgradeCode (setup project properties) needs to be the same so don't change it.
Increment the file versions of the binaries that need updating (that's the standard rule about updating versioned binaries).
The resulting MSI will do a major upgrade (in Windows Installer terminology) and upgrade the older version, replacing it with your new product MSI. Note that an upgrade will work only with the same context of install. An Everyone will not upgrade a Just me, so that will result in two entries in Programs and Features. Doing the install creating a verbose log and searching foe FindRelatedProducts entries will tell you if it found the upgrade or not. msiexec /I [path to msi file] /l*vx [path to a text log file]
There's a longer explanation here:
https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/?_ga=2.138201520.1662048302.1514485579-1682631157.1514485579
which is old but relevant. and doesn't mention the requirement to update binary file versions (it wasn't needed with early VS setup projects).

How do I get Eclipse CDT to ignore files

I have a C++ project in Eclipse. The project uses Perforce and Eclipse has the Perforce plugin installed. Everything was fine, until I decided to create a git repo in my project. I created the git repo to snapshot some changes which I wasn't ready to commit. Everything was fine until I refreshed my files in Eclipse. Two problems have occurred:
Eclipse found my .git folder, and indexed all of the files inside of it.
Eclipse also decided to add all the git file to my pending change list.
If I create a new file within Eclipse, I'd like it to add it to Perforce, but if it happens to find a file, I don't want it to do anything with it. I'd also like to give Eclipse a list of file types to always ignore, just like I do with my .gitignore file.
I'm using the P4WSAD plugin, but I'm pretty sure the problem can occur anytime you have files you want Eclipse to not see.
Just add a file .p4ignore in your project root and add everything you want P4WSAD to ignore, such as
.git
See the docu on P4WSAD for more info.
That should take care of the Perforce part of your question. For the Eclipse part, please see this SO question.