update or downgrade .csproj file after nuget restore packages from packages.config - nuget-package

I have many VSTS builds which has reference to one nuget package. Depending on primiary build we have to sometimes to upgrade/downgrade nuget package in VSTS build. We are doing this by copying packages.config with proper version, then we use nuget restore. My problem is that after upgrade/downgrade of nuget package .csproj file still have old version od package reference, so when build starts it still try to search for old reference from .csproj file and build fails.
I there any way to change .csproj file after nuget restore?

No, there is no way to update the .csproj during the build. You should change the .csproj locally and then build in VSTS.
Except the way manually changed the .csproj file, there has an easier way to change package versions correspondingly in .csproj. Execute below command in Package Manager Console window:
update-package -reinstall
So the workflow to use upgrade/downgrade nuget package version as below:
Change the versions in package.config file.
Run the command update-package -reinstall in in Package Manager Console window.
Commit and push/checkin the changes to remote repo.
Build your project in VSTS with the upgrade/downgrade nuget package version reference.

Related

Nuget package readme.txt is not being updated

I followed the steps to create and publish a nuget package including a readme.txt. (https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio?tabs=netcore-cli)
The initial version of the readme.txt correctly opens when the package is installed. But, I made changes to the readme.txt, re-packed it, re-added it to my local nuget feed (I deleted the previous), and when I install it, it opens the initial version of the readme.txt. My changes are not in it.
The dates of the package are updated in both my bin\Release and C:\LocalNugetPackageFeed\packages.
At first, I was thinking the issue was that my package was not grabbing the latest version of the readme.txt. Here, it's because my package was being cached. To fix the issue, I went to Tools > Options > NuGet Package Manager > General > Clear All NuGet Cache(s).
After doing this, my updated readme.txt would show after installing the package.

Unable to deploy app with nuget references on server

I am having a hard time deploying my first .net core app with nuget references on the server. Locally, the app works absolutely fine (able to use nuget packages).
Apparently, there is no packages.config. I am using Dapper, Newtonsoft.Json, etc. Where is the project storing reference to these packages? There is no packages folder.
In the solutions folder, there is nuget.config file which for some reason is empty.
What should I add here
Unable to deploy app with nuget references on server
That because you are using the old version nuget restore task in the build pipeline, which only supports for the package management type packages.config not PackageReference.
That the reason why the old version task ask you to provide the path to the packages.config. The PackageReference is a follow-up product, so the previous version of nuget restore task does not support it.
Check the blog for some more details.
To resolve this issue, please use the V2 of the nuget restore task:
Note:
The PackageReference needs the nuget.exe 4.1 and above, please add
a NuGet tool installer to install the nuget version above 4.1.
Using .NET Core restore task should be also work for this issue.
Update:
Yes, using TFS 2016
Since you are using TFS 2016, you could try to use the command line to invoke the nuget.exe to restore the package instead of the nuget installer task:
Download the nuget.exe above 4.0 from the nuget.org, then set it on the TFS server.
Hope this helps.
You need to create a NuGet.config file that points to whatever NuGet feed you're using, add it to source control, and reference it in your build. I'll use the official feed for my example. This feed is already present by default if you're developing using Visual Studio, which might explain why the build runs locally but not on Azure DevOps.
At the very least, your NuGet.config file needs to look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet.org Feed" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
In .NET Core, packages are now stored globally in your User directory. packages.config has been dropped in favor of the PackageReference node in a project file, so check your csproj to see the NuGets you're referencing.
You should use task dotnetcorecli task which has
#command: 'build' # Options: build, push, pack, publish, restore, run, test, custom

SlowCheetah 2.5.48 not transforming web config on build

So I have downloaded the latest SlowCheetah Visual Studio Extension v2.5.48.45331 and installed the latest NuGet Package. I have a custom build configuration named XL.Production and have the according Web.XL.Production.config file. When I publish, Web.XL.Production.config is picked up and everything's sugar, but when I hit F5, no go, Web.config settings are used even though XL.Production configuration is currently selected.
I have checked out this question: SlowCheetah not transforming file on build
But the latest SlowCheetah is not using PropertyGroup any longer and instead relies on the NuGet Package.
So it's not working for me, it was clean install, we never had any previous version of SlowCheetah installed. We are using VS2013 w/Update 5.
p.s. Just a thought, why is such a critical functionality not built in into VS by default? Why should I have to install a NuGet package and a Visual Studio Extension to get this to work?

Appveyor not calling Nuget Pack

On my Appveyor project here I have it configured in the build with Package NuGet projects checked. And in my source code I have a .csproj with a matching .nuspec here but my build isn't calling nuget pack to create the .nupkg file.
What am I missing?
The problem was that I had an incorrect configuration in my appveyor.yml file. I updated the file to be only this and it started working.
version: '2.0.0.{build}-prerelease'
build:
publish_nuget: true

NuGet Package restore failed for project myProjectWeb: Unable to find version '3.0.1' of package 'AppForSharePoint16WebToolkit'

It's a provider hosted project. It used to work until very recently.
If I create a completely new project/solution, then it works.
If I start the old one, or redownload it from source control, I get the following error:
NuGet Package restore failed for project LocalTheaterWeb: Unable to find version '3.0.1' of package 'AppForSharePoint16WebToolkit'
I tried Update-Package -Reinstall but the problem stays.
Any ideas?
The solution of Scott Hillier did it for me:
http://www.shillier.com/archive/2014/08/05/nuget-package-restore-fails-for-sharepoint-2013-provider-hosted-apps.aspx
I often take advantage of the NuGet Package Restore capability to
reduce the size of my projects when saving or sharing them. Today, I
discovered an issue with this process when building SharePoint 2013
Provider-Hosted Apps against SharePoint Online. Here are the steps to
reproduce and the fix:
Create a Provider-Hosted App in Visual Studio 2013 using a SharePoint Online site for debugging.
Right click solution and "Enable NuGet Package Restore"
Save and Close Project
Delete the “packages” folder from project directory
Open Project in Visual Studio 2013
Rebuild, receive error “Unable to find AppForSharePoint16WebToolkit”
Open Packages.config file
Change “AppForSharePoint16WebToolkit” to “AppForSharePointWebToolkit”
Rebuild – successfully this time. Apparently, the "AppForSharePoint16WebToolkit" package is not available through the
NuGet Package Manager, but the older "AppForSharePointWebToolkit"
package is available.
The error message suggests that NuGet cannot find the AppForSharePoint16WebToolkit package in your package sources. So check the following:
The correct package source is selected whilst doing the Update-Package -Reinstall.
Check the package source that hosts the NuGet package is enabled. If you are using a recent version of NuGet the package restore should use all the enabled package sources.
See if the solution or project has its own NuGet.config which is overriding the package sources.
Without further information my guess is 3. since you say it works for a new project.
You can also run Fiddler to see what package sources NuGet is using as it tries to restore.
For older "locked down" projects with specific package version numbers that you can't update, un-check "Automatically check for missing packages during build in Visual Studio" which is found via:
Nuget Package Manager > Package Manager Settings
This means that if you toggle between newer projects and older projects you need to check and un-check this setting

Resources