NuGet package version is ignored when building - visual-studio-2017

I am using VS 2017. I have this line in my packages.config file.
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.4.403061554" targetFramework="net461" />
I got this error my trying to start my .net application.
System.TypeLoadException: Could not load type 'System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Because System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause really does not exist in version 5.2.1.0. But it seem NuGet simply ignores the version specification, and always loads the latest version.
I have tried to clean NuGet caches, clean and rebuild entire solution, and restart computer...
Is there anything else I can do?
Update
One strange thing I observed in VS 2017. Notice the differences of the icons for System.Data and System.IdentityModel.Tokens.Jwt. When I try to check the properties of the latter, VS says the package is not installed, which it clearly did. The build went successful, but the application just wont load the right version.

There are a couple of steps you can perform to check that the right version is loaded:
Rebuild your solution to make sure all NuGet packages are restored and that the started application is up to date (You already did that).
Check the tag HintPath for the reference in the project file that references the package. Just open the file in a text editor and look for an XML tag starting with <Reference Include="System.IdentityModel.Tokens.Jwt. Make sure that no version-specific reference is set or that the version matches the version in the packages.config file.
Check in the properties of the according reference in Visual Studio that it is resolved correctly. That means, there must be no yellow exclamation-mark icon on the reference in the solution explorer and in the properties of the reference, the Path entry must point to the installed package. Hence, the path should point to the packages directory inside your solution directory and therein into a directory System.IdentityModel.Tokens.Jwt.4.0.4.403061554.
In most cases (from my experience), there is some mismatch between the reference in the packages.config file and in the project file. If that does not help, make sure that no other module is loaded by your application that has a reference to System.IdentityModel.Tokens.Jwt in version 5.2.1.0.

So far, it is still unclear why VS cannot handle the changes of the NuGet packages, and why it thinks my project is using both .Net Framework and .Net Standard at the same time. I bet it is a but in VS, and hope MS can fix it soon.
Before that, installing Rider and use it to fix the packages, then went back to VS, and everything went back to normal.

Related

VS 2017 Setup Project wouldn't install in C:\DestFolder\

Due to the administrative privilege of the application, I need to install my program including .exe and .dll in C:\DestFolder\SubFolder\ but I keep getting C:\Program Files\\[Manufacturer]\\[Product Name]\ where the placeholders are specified in the properties window.
I tried this article but no good.
Please don't give me answer like try changing the defaultlocation to C:\Destination\ of the Application Folder as I have already tried. Also I don't want solution like just change the installation destination path manually during the installation.
I have found the answer from this article:
"[ProgramFilesFolder] is built in, and correctly leads to the Program Files directory on the target machine, no matter how customized the setup of Window is..."
There might be tools out there that allow installing outside of Program Files.
[Edit] Infact I've found out this great extension for VS 2017 community called Wix. There's a guy who did a fabulous tutorial on it.

Where can I download the latest version of VSLangProj150

I'm looking for the current version of VSLangProj150.dll but I can't seem to find it anywhere.
I have this version, VSLangProj150.15.0.26228 retrieved from nuget but I believe this is an old version because: 1) it was published on 4/13/2017 and 2) it only contains a single interface called PackageReferences which is empty and a VsProjReferencesPropId150 enum with only two values.
Today, I've installed VS 2017 v15.5 and included the Visual Studio SDK component, but I can't seem to find the dll anywhere on my system.
It appears that there is a new version because I've seen references on the web that refers to VSProject4 and Reference6 which are defined in VSLangProj150. And I've found this reference in NuGet.Clients that reads:
AsVsProject4.PackageRefereences?.InstalledPackages
Or am I missing something?
Found it! Must manually get it from nuget.org using VSLangProj150 Version 1.0.0 or as I did, I just added the following:
<package id="VSLangProj150" version="1.0.0" targetFramework="net46" />
to my packages.config file and then let VS 2017 automatically restore any of my missing packages!

Your project is not referencing the "UAP,Version=v10.0.10240" framework

I am using Visual Studio Community Edition 2017 and trying to create a UWP application.
I get the following error
Your project is not referencing the "UAP,Version=v10.0.10240" framework. Add a reference to "UAP,Version=v10.0.10240" in the "frameworks" section of your project.json, and then re-run NuGet restore.
I had the same issue on my build machine. What's weird is everything runs fine on my local machine.
I managed to fix this by going into the project properties for my UWP app, and changing the Target version to match the Min version.
The reason I believe this issue is happening is because when targeting a higher framework, on a Windows Server machine (the build agent) it doesn't restore all of the packages between your min and target version. It seems to build fine against the version you target.
By the way Ken, following the instructions given by the error don't fix the issue. Try not to be so rude. I came to this page looking for the same issue, and you are no help at all.
I have the same issue, after I remove my bin and obj folder, I can build mine and see the errors gone.
I recently ran across this same issue when updating the target framework. The issue turned out to be the Nuget Restore task in my VSTS Build definition needed to be updated to the latest version (2.*). Once I did that, the builds worked as expected.
I agree with Jeff. Ken Not sure if you should be giving any answers with this kind of attitude.
The error message is misleading there is not project.json at least you cannot see it in the Visual Studio explorer.
I had the same issue and have min and target version set to the same number but it would not build.
The fix was to make sure in Nuget package manager setting to tick checkbox 'Allow Nuget to download missing packages' and the one below it as well and rebuild the project.
This is a pretty weird mistake, but what worked for me :
1st Solution:
1 - Change your project target to "10.0.10586" (or up)
2 - Make a clean / nuget restore / rebuild
3 - Return the project target to the "10.0.10240"
4 - Make a clean / nuget restore / rebuild
Do not ask me why, but it worked :)
2nd Solution:
If you use a repository with Tortoise, try making a CLEANUP
I had an old Backup folder in my project that contained a project.json. Looks like it might have been from an earlier upgrade. I deleted Backup and got a good build.
This happens in exactly this manner, if projects were generated in the year 2017 in the phase where MS changed to project.json and then decided against it. I tried several solutions (and yeah, Ken White is so wrong!) and the cleanest way was to really build up a new clean project in the lastest and up to date version of Visual Studio (VS2015 did not work sustainable) and just copy over the old project content which is just a few minutes work. This will save you a lot of headaches especially working in a larger team!
I tried the above solutions but nothing worked. I had to backup and remove the UWP project and recreate it from scratch.
I tried a couple of solutions.
Solution 1
Open the solution from Windows explorer and search for project.json files. Open all of them (If you have multiple) and make sure the required framework versions are there. I frequently switch between build 10240 and 17763 and I get this error frequently. (I switch between git branches that target different frameworks of UWP) So instead of adding the exact version I just added only the 10.0 part like this.
"frameworks": {
"uap10.0": {}
},
Now if your project.json files are ok, search for project.lock.json files. If you have one or more of those, delete them.
Now clean your solution
Close VS
Delete all the bin and obj folders.
Reopen the VS and try to run the app.
Solution 2:
Go to project properties
Change the minimum and target version to something else and do a clean build. Then put the actual versions and build again.

Netstandard.Library 1.6.1 blocked by project

I've created a brand new solution and project in VS2017 RC and for some reason I can't use the latest version of the NETStandard.Library package.
There's no code in the project and it's the first project in the solution.
When in the NuGet package manager it's listed in the dropdown, but marked as blocked by project.
Any ideas?
You need to execute the command in Package manager console for your project
Install-Package NETStandard.Library
The NETStandard.Library package is no longer meant to be upgradable through the package management UI. The "SDK" component of the project emits this reference automatically and marked read-only.
This behaviour can be overridden through a property in the csproj file:
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
If you delete a line like this from your csproj file, you'll get the newest version that VS or the CLI knows about.
This property is usually added when migrating from project.json to csproj. In this case, you can safely remove it.

VS2017 RC1 Installation installation error - Microsoft.PortableLibrary.TargetingPack.Msi failed - No XAML

I had errors installing VS2017 with
Package 'Microsoft.PortableLibrary.TargetingPack.Msi,version=15.0.26004.1' failed to install
The actual IDE will open but I don't have any XAML functionality - it appeared to fail the installation before this component was installed. XAML files won't load and there is no XAML listed under 'Text Editor'.
How to fix this error?
After several hours finally managed to get it to work:
Still not sure exactly what a targeting pack is - and why VS couldn't install it but I manually installed this package and managed to get it to work:
Manually installed:
Microsoft .NET Framework 4.6.2 Developer Pack and Language Packs
https://www.microsoft.com/en-us/download/details.aspx?id=53321
Other things I did that may have contributed to the solution:
I rebooted
I removed all files in C:\ProgramData\Microsoft\VisualStudio\Packages - actually I moved them to an OLD folder and later deleted them. You will see packages downloaded here after you restart the install.
I had previously created a symbolic link from %ProgramData%\Package Cache to another drive to save space (https://superuser.com/questions/455853/can-i-delete-the-folder-c-programdata-package-cache). This symbolic link didn't seem to work anymore leaving me with some files in %ProgramData%\Package Cache and the rest in the other drive. I moved them over and recreated the link. If this is something you did to save disk space and forgot then that could contribute towards a failed solution.
Something above fixed the issue and I now have XAML back again.
Note: The VS2017 RC1 does not support offline installation so that was another avenue I explored and gave up on. The command line switches currently do NOTHING.
I believe the package I needed is the following one but not absolutely sure.
C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.PortableLibrary.TargetingPack.Msi,version=15.0.25719.0