C
C#•2y ago
P R Deltoid

āœ… Compiling ASP.NET 7 app using Github Actions

I am trying to compile my ASP.NET 7 application solution using Github actions but am getting the following error: error CS0234: The type or namespace name 'Authentication' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) when building a project that requires this package. My github action looks like this:
name: .NET

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

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
name: .NET

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

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
I figured the GitHub Action's dotnet setup would have included these files. I know this isn't exactly a C# question but I figured people here might have experience with this particular problem. I'm a little confused on how my local build could find these files but the Github Action build cannot Probably related, but I am also receiving warnings: Could not locate the assembly "Microsoft.AspNetCore.Http.Features" Could not locate the assembly "Microsoft.AspNetCore.Authentication.Cookies"
54 Replies
Henkypenky
Henkypenky•2y ago
you don't need the dotnet restore try
- name: Set up .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
- name: Set up .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
and get rid of --no-restore dotnet build already runs restore
P R Deltoid
P R DeltoidOP•2y ago
I think it's split into two to make the errors more separated depending on which process fails it's the template straight from Github, I just changed 6.0.x to 7.0.x do you think the restore being separate is the issue?
Henkypenky
Henkypenky•2y ago
maybe can you try my suggestions ?
P R Deltoid
P R DeltoidOP•2y ago
trying the change of version number right now
Henkypenky
Henkypenky•2y ago
name: .NET

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
- name: Build
run: dotnet build --configuration Release
- name: Test
run: dotnet test --no-build --verbosity normal
name: .NET

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
- name: Build
run: dotnet build --configuration Release
- name: Test
run: dotnet test --no-build --verbosity normal
P R Deltoid
P R DeltoidOP•2y ago
made all the changes you suggested, same error occurrs
Henkypenky
Henkypenky•2y ago
at what step does the error occur?
P R Deltoid
P R DeltoidOP•2y ago
the build after it restores the projects in the solution, it lists the two warnings, and then the error
Henkypenky
Henkypenky•2y ago
is this an upgrade from an old .net version?
P R Deltoid
P R DeltoidOP•2y ago
Shouldn't be but I may have upgraded directly after making the project
Henkypenky
Henkypenky•2y ago
can you try running on windows runs-on: windows-latest i think you are missing a packagereference or does it build fine on your IDE?
P R Deltoid
P R DeltoidOP•2y ago
It builds just fine, but it could be the IDE is doing something for me that I just don't know about? builds fine locally, I mean
Henkypenky
Henkypenky•2y ago
it should work in github then try windows let me know
P R Deltoid
P R DeltoidOP•2y ago
building rn. Much slower than ubuntu 😦
Henkypenky
Henkypenky•2y ago
yeah
P R Deltoid
P R DeltoidOP•2y ago
Same error
Henkypenky
Henkypenky•2y ago
damn
P R Deltoid
P R DeltoidOP•2y ago
so I don't have a PackageReference for Microsoft.AspNetCore.Authentication in my project file, could that be part of the issue? It's not a NuGet package, it's from the SDK
Henkypenky
Henkypenky•2y ago
you shouldn't need to can you share your cs proj?
P R Deltoid
P R DeltoidOP•2y ago
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.100.129" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.2.23128.3" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.15.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.1" />
<PackageReference Include="zxcvbn-core" Version="7.0.92" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Authentication.Cookies">
<HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\7.0.4\Microsoft.AspNetCore.Authentication.Cookies.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Features">
<HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\7.0.4\Microsoft.AspNetCore.Http.Features.dll</HintPath>
</Reference>
</ItemGroup>

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

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

<ItemGroup>
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.100.129" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.2.23128.3" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.15.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.1" />
<PackageReference Include="zxcvbn-core" Version="7.0.92" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Authentication.Cookies">
<HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\7.0.4\Microsoft.AspNetCore.Authentication.Cookies.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Features">
<HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\7.0.4\Microsoft.AspNetCore.Http.Features.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
Those Reference Includes with the long relative path look kinda suspicious
Henkypenky
Henkypenky•2y ago
get rid of those, and run dotnet build see if it builds fine that's the issue, github can't find those references
P R Deltoid
P R DeltoidOP•2y ago
Now it throws the same error as Github Okay, so how do I do this the right way?
Henkypenky
Henkypenky•2y ago
get those packages via nuget or are they private? they all seem nuget
P R Deltoid
P R DeltoidOP•2y ago
I think they're copied straight from the .net7 sdk I can't find them on NuGet not the version I have locally only deprecated versions
Henkypenky
Henkypenky•2y ago
they are part of the sdk if you need them like that github needs them
P R Deltoid
P R DeltoidOP•2y ago
I th ought that is what the dotnet-setup action was taking care of. Installing the SDK or whatever
Henkypenky
Henkypenky•2y ago
but if you get rid of them where in the code does it throw errors add a using
P R Deltoid
P R DeltoidOP•2y ago
At a using Microsoft.AspNetCore.Authentication.Cookies; call
Henkypenky
Henkypenky•2y ago
remove it where does it break
P R Deltoid
P R DeltoidOP•2y ago
The CookieAuthenticationDefaults in this line: ClaimsIdentity claimIdent = new(claims, CookieAuthenticationDefaults.AuthenticationScheme); I am realizing my IDE's build button doesn't generate the error but dotnet build does šŸ˜•
Henkypenky
Henkypenky•2y ago
maybe the ide is fixing it automatically is this a class library?
P R Deltoid
P R DeltoidOP•2y ago
Yeah
Henkypenky
Henkypenky•2y ago
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
try that dotnet build
P R Deltoid
P R DeltoidOP•2y ago
nice! That worked
Henkypenky
Henkypenky•2y ago
excellent now try github, you can go back to ubuntu
P R Deltoid
P R DeltoidOP•2y ago
The IDE's auto-import did that relative path crap instead of this, dunno why
Henkypenky
Henkypenky•2y ago
yeah so the problem is that they are part of the SDK but they are part of Sdk.Web and that's not included in the core sdk
P R Deltoid
P R DeltoidOP•2y ago
I just dunno why it decided to do that janky relative path instead of this FrameworkReference option
Henkypenky
Henkypenky•2y ago
someone did that probably
P R Deltoid
P R DeltoidOP•2y ago
Made the project non-portable
Henkypenky
Henkypenky•2y ago
absolutely
P R Deltoid
P R DeltoidOP•2y ago
It was definitely the IDE doing it, I can recreate it by using the quick action to import that library oh well
Henkypenky
Henkypenky•2y ago
yeah the IDE fixes a lot of things
P R Deltoid
P R DeltoidOP•2y ago
this is excellent, learned a lot too ty for your help
Henkypenky
Henkypenky•2y ago
no worries
P R Deltoid
P R DeltoidOP•2y ago
gonna double-check github now
Henkypenky
Henkypenky•2y ago
let me know go back to ubuntu xd
P R Deltoid
P R DeltoidOP•2y ago
Nice! Now it's a build error I expected instead of the issue with references. Thanks again.
Henkypenky
Henkypenky•2y ago
amazing! well that you can fix i hope haha
P R Deltoid
P R DeltoidOP•2y ago
yeah, I know what to do B-)
Henkypenky
Henkypenky•2y ago
Ok
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
P R Deltoid
P R DeltoidOP•2y ago
It's a class library. I think we got the issue sorted though IDE was referencing asp.net libraries with a weird relative path instead of a framework reference
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?