C
C#13mo ago
Alexicon

❔ Git Hub Actions Dot Net Push keeps trying to use 1.0.0.nupkg but that file should not exist

I have an established GitHub workflow I have been using for a while that builds, tests and pushes NuGet packages for a large C# library solution.
name: Build and Publish Nuget Packages

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Install .NET 7
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.x

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore /p:VersionPrefix=7.0.$env:GITHUB_RUN_NUMBER

- name: Test
run: dotnet test --verbosity normal

- name: Push
run: dotnet nuget push */**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
name: Build and Publish Nuget Packages

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Install .NET 7
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.x

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore /p:VersionPrefix=7.0.$env:GITHUB_RUN_NUMBER

- name: Test
run: dotnet test --verbosity normal

- name: Push
run: dotnet nuget push */**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
This workflow has been working for ages doing exactly what I want which is to package all the projects into NuGet packages for me, where the version of those packages is 7.0.[run number]. However I just recently added a new C# class library project to the solution, and I am getting a frustrating issue with this workflow. Now even though the new project is set up identically to all the others it keeps trying to push a myproject.1.0.0.nupkg file instead of one with the 7.0.[run number].
Pushing MyProject.1.0.0.nupkg to 'https://www.nuget.org/api/v2/package'...
Pushing MyProject.1.0.0.nupkg to 'https://www.nuget.org/api/v2/package'...
Whats odd is that this file should not even exist since as you saw in the workflow, I specify that the version prefix should end with the GitHub run number and start with 7.0.
/p:VersionPrefix=7.0.$env:GITHUB_RUN_NUMBER
/p:VersionPrefix=7.0.$env:GITHUB_RUN_NUMBER
[continued below]
13 Replies
Alexicon
AlexiconOP13mo ago
I cant figure out why this new project doesn’t work like the rest and is not correctly pushed as a 7.0.[run number] version. I can even see in the build logs of the workflow that the correct nupkg file is being created.
MyProject -> D:\a\MyRepo\MyRepo\MyProject\bin\Release\net7.0\MyProject.dll
Successfully created package 'D:\a\MyRepo\MyRepo\MyProject\bin\Release\MyProject.7.0.49.nupkg'.
MyProject -> D:\a\MyRepo\MyRepo\MyProject\bin\Release\net7.0\MyProject.dll
Successfully created package 'D:\a\MyRepo\MyRepo\MyProject\bin\Release\MyProject.7.0.49.nupkg'.
The project’s csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>

<Authors>...</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>...</Description>
<Copyright>...</Copyright>
<PackageProjectUrl>...</PackageProjectUrl>
<RepositoryUrl>...</RepositoryUrl>
<RepositoryType>...</RepositoryType>
<PackageTags>...</PackageTags>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>

<Authors>...</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>...</Description>
<Copyright>...</Copyright>
<PackageProjectUrl>...</PackageProjectUrl>
<RepositoryUrl>...</RepositoryUrl>
<RepositoryType>...</RepositoryType>
<PackageTags>...</PackageTags>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>
I also thought maybe the 1.0.0.nupkg file was pushed in a commit by accident but it does not exist in the git repo and is correctly part of the .gitignore anyway. The only other new thing that I did was add an x-unit test project and the dot net test part of the workflow but that should not cause any issues I wouldn't think. It’s been impossible to google this specific issue since everything just takes me to how to push NuGet packages which I already know how to do. If you need the concrete details, you can view this on the actual GitHub page since this repo is public: https://github.com/AlexLexicon/Lexicom/actions/runs/6701136141/job/18208104259
GitHub
fixed maths unit test · AlexLexicon/Lexicom@de81047
Contribute to AlexLexicon/Lexicom development by creating an account on GitHub.
Alexicon
AlexiconOP13mo ago
I have to assume that I have missed something but at this point I feel like I have looked over everything and nothing seems incorrect or different than what I had before.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Alexicon
AlexiconOP13mo ago
@TeBeClone if I run a simple dotnet build locally like the following:
dotnet build --configuration Release --no-restore /p:VersionPrefix=7.0.12345
dotnet build --configuration Release --no-restore /p:VersionPrefix=7.0.12345
I do see the correct package being generated
Successfully created package 'C:\Users\alexr\source\repos\Lexicom\Lexicom.Maths\bin\Release\Lexicom.Maths.7.0.12345.n
upkg'.
Successfully created package 'C:\Users\alexr\source\repos\Lexicom\Lexicom.Maths\bin\Release\Lexicom.Maths.7.0.12345.n
upkg'.
and the release folder on my file system only contains the 'Lexicom.Maths.7.0.12345.nupkg' file and not a 'Lexicom.Maths.1.0.0.nupkg'. In your screenshot I can see that the package that was created was in the debug folder but my yml pipeline builds for release configuration and shouldnt generate any debug output I wouldn't think
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Alexicon
AlexiconOP13mo ago
oh sorry the nuspec was a mistake on my part, they are nupkg files not nuspec. I will edit my response accordingly
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Alexicon
AlexiconOP13mo ago
Maybe I am confused about something, where did you take that screenshot exactly?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Alexicon
AlexiconOP13mo ago
Wow, I should have thought of that. You were correct, the test was re-building the solution causing it to generate packages again, I guess. To fix it all I had to change was the dotnet test to the following:
run: dotnet test --no-build --configuration Release --verbosity normal
run: dotnet test --no-build --configuration Release --verbosity normal
Which makes complete sense now that I look at it. Thanks for helping me with this! /close
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Alexicon
AlexiconOP13mo ago
I can see the value in that format but to be honest I will probably leave it as is since I prefer this setup for what I need from it.
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server