Increment Nuget package version on publish or release build - c#

I am wondering if there is a way to make my project increment the nuget package version everytime I publish/build it? I tried adding the AppxAutoIncrementPackageRevision property to my csproj file but it didn't seem to help. If this is not possible, maybe it is possible to increase the version everytime I do a release build?
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<Version>1.0.0</Version>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
</PropertyGroup>
Found this for example: Can I automatically increment the file build version when using Visual Studio?
But its for Visual Studio 2008.

Related

Visual Studio 2022 Mac Error: NuGet packages need to be restored before building. NuGet MSBuild targets are missing and are needed for building

I have a .Net 6 project, I am getting the below error.
Error: NuGet packages need to be restored before building. NuGet
MSBuild targets are missing and are needed for building. The NuGet
MSBuild targets are generated when the NuGet packages are restored.
csproj file:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Visual studio version: 17.4.2
I have followed this question also (restoring the packages), But it didn't help.
But I am able to build from the terminal using dotnet build successfully.
Also, I have other projects targeting .net 6 and I can build successfully using visual studio.

visual studio 2019 .csproj install latest NuGet version

I have a very simple VS2019 .csproj file which can be seen below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AST.NxTestware.main" Version="1.0.0" />
</ItemGroup>
</Project>
When I save the csproj file, I can see in my right hand side the dependency is downloaded, and I can find the installed NuGet package on my PC
Under the manage nuget package window I can see a newer version 1.1.0
I want to edit my .csproj file so that it always installs the most recent NuGet package version, and I tried doing so by setting version="*"
https://learn.microsoft.com/en-us/nuget/concepts/package-versioning
but setting version=* causes my VS2019 dependency list to show a yellow warning circle now which wont go away, and if I check my local NuGet installation folder I can see that nothing got installed
How can I tell VS2019 to automatically install the latest version of my NuGet package?
According to your description, I did some tests related to your problem, but could not reproduce your problem.
You can try these suggestions and let me know if it doesn't work.
You can go to Tools>Options>NuGet Package Manager to Clear All NuGet Caches. Add this in your .csproj file “” and rebuild the project.
You can change a package source to check if other packages can use Version=”*”.
Please let me know If you get any update about the issue.

Error "NU1101: Unable to find package xyz" with dotnet publish .NET 5 and win-x64

I'm trying to publish the most barebone WinForms app as single file, it is just a button that shows a MessageBox, targeting Windows and .NET 5.
I have installed .NET SDK 5.0.102, then VS 16.8.5 which installed 5.0.103.
I've got some other errors earlier when trying to publish the app, and by googling here and there I got to this point.
Now dotnet publish fails with this error:
path.csproj : error NU1101: Unable to find package packagename. No packages exist with this id in source(s) (etc).
Three times, with these packages missing:
Microsoft.NETCore.App.Runtime.win-x64
Microsoft.WindowsDesktop.App.Runtime.win-x64
Microsoft.AspNetCore.App.Runtime.win-x64
It is an offline computer, so I understand the "issue", even though I don't understand why the SDK installation or VS aren't also dumping all the packages somewhere on the disk.
However, if I go to the NuGet page for these packages, their description is:
"Internal implementation package not meant for direct consumption. Please do not reference directly."
And that makes me think that there must be another way to properly fix this problem.
What am I supposed to do?
Thank you!
Update/Edit to add more details and the .csproj file:
It is a clean Windows 7 Ultimate x64 installation with rollups up to 2019-12 (because 2020-01 has issues).
There is no antivirus or other software that could interfere, I've only installed drivers, .NET SDK 5.0.102, .NET Framework 4.7.2 SDK, then installed Visual Studio 2019 16.8.5 from a layout (verified), and VS also installed .NET SDK version 5.0.103 "from Visual Studio".
This is what I do:
Open Visual Studio, create a new project using template "Windows Forms App (.NET)". I've also tried with leaving its default name and location, but I never use names with spaces or non-English letters and numbers anyway.
If I just launch the app from the editor, it builds and works fine.
Then I open Developer Command Prompt and run this:
dotnet publish -c Release -r win-x64 --self-contained true
I get the above errors. Same with just:
dotnet publish -c Release -r win-x64
This is the untouched .csproj file:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
If I change the target framework to .NET 5.0 the .csproj file stays the same, except for TargetFramework, which changes to 'net5.0-windows'. Then I get the Warning NETSDK1137 (It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'.), but whether I change that or not, the errors when publishing stay the same as before.
I've also tried changing the .csproj file to the one in this page:
https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file
(Tried with it entirely as it is there, or by just adding some missing properties, if anything I would get other errors that way.)
If I try other ways to publish instead of using the command line, I still get errors.
I think you have some wrong PackageReference node under your csproj file.
I think you have added like these on your csproj file:
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App.Runtime.win-x64" Version="5.0.3"></PackageReference>
<PackageReference Include="Microsoft.WindowsDesktop.App.Runtime.win-x64" Version="5.0.3"></PackageReference>
<PackageReference Include="Microsoft.AspNetCore.App.Runtime.win-x64" Version="5.0.3"></PackageReference>
</ItemGroup>
If so, you should note that these are internal implementation runtime packages for Net5.0, and they are not installed by nuget.
And they are still contained under Net Core 5.0 Sdk. If you change your Platfrom to x64, it already enables these runtime packages.
So please remove these xml node and then re-publish your winform project.
Besides, if the issue still persists, please share your csproj file with us and we could troubleshoot the issue more puickly.

Force evaluate floating version packages with lock file via MsBuild / csproj

I want to use the Locking dependencies of Nuget (>= 4.9), so I can have automatic package update during dev phase and fixed version during release build.
I enabled the lock file mode, so I now have a packages.lock.json file.
The problem is that when I have floating version of package references in the project file like:
<PackageReference Include="My.Nuget.Package" Version="1.0.*" />
The restore package via Visual Studio Build does not update to new packages version anymore. This behavior appeared after I activated the lock file.
The Microsoft documentation describes the --force-evaluate option with dotnet.exe, that works well but I want to do this directly with an MsBuild option in the csproj.
By checking the NuGet Client code, it seems that a RestoreForceEvaluate option exists in Msbuild NuGet.targets but I have no idea how to use it.
By checking the NuGet Client code, it seems that a RestoreForceEvaluate option exists in Msbuild NuGet.targets but I have no idea how to use it.
I am afraid we could not do that at this moment. According to the nuget wiki,
Enable repeatable package restore using lock file:
There is no such MSBuild equivalent option for option --force-evaluate, so we could not use --force-evaluate directly with an MsBuild option in the csproj.
Hope this helps.

VS.NET 2017 forces using StackExchange.Redis 1.2.4.0 in ASP.NET 2.0 Core app

I am using Visual Studio 2017. I just created a new ASP.NET Core 2.0 project. I was trying to use NuGet to pull in the latest StackExchange.Redis 1.2.6 (as of 9/3/2017).
However, once I do that, Visual Studio complains that there is a conflicted reference in one of my RedisResult variable. It said
Error CS0433 The type 'RedisResult' exists in both 'StackExchange.Redis.StrongName, Version=1.2.4.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis, Version=1.2.6.0, Culture=neutral, PublicKeyToken=null' Server C:\git\Splash\Server\BackPlaneConnection\Channel.cs 19 Active
Then, I found out that I don't really need to manually add any NuGet package in order to use StackExchange.Redis in my ASP.NET Core 2.0 app. In fact, if I manually add a reference to a different version of StackExchange.Redis, it causes the resolve conflict that I showed above.
Checked the build output. The DLL is actually coming from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\stackexchange.redis.strongname
I tried deleting stackexchange.redis.strongname but it somehow still download it to my personal nuget folder automatically.
It almost feels like ASP.NET Core 2.0 internally needs StackExchange.Redis 1.2.4.0 but this really doesn't make sense to me.
I don't have the same problem when using ASP.NET Core 1.1. Is there any way to let my ASP.NET Core 2.0 use the latest StackExchange.Redis from NuGet?
Found the reason. It's because by default VS.NET 2017 turned on the "Allow NuGet to download missing packages". The build screen also mentioned that.
Restoring NuGet packages...
To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.'
In my case, to completely avoid this problem, I need to do the following steps to resolve my problem.
Go to Visual Studio Options dialog.
Uncheck "Allow NuGet to download missing packages" to avoid downloading the NuGet package automatically in the future
Open NuGet Manager to add the latest StackExchange.Redis package
Click "Clear All NuGet Cache(s)" to clean up the old NuGet cache
I added a conditional flag to the "StackExchange.Redis" package, that makes it work. I Tried this fix on two new projects on two machines. Don't ask me why it works tho.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="StackExchange.Redis" Version="1.2.6" />
</ItemGroup>
</Project>
I gave the same answer in my duplicate question
I just ran into a similar problem in a solution file with a number of projects in it. A nuget package had been added which contained a dependency to a *.StrongName.dll version of a package that was already included in one of the projects. Since it was a dependency, tracking down where the StrongName version was referenced was extremely difficult even though it appeared in the Object Browser. I was finally able to track it down using a PowerShell console to dig through all nuget project dependencies in all projects to find the source of the duplication:
dir -Recurse **\project.assets.json | Select-String -pattern "{{dll name}}"

Categories

Resources