Gitlab-CI deploy different files from local deploy for .net core

0

I have a gitlab-ci pipeline. When merge to develop branch, it is publishing to test server. But, there is an error when Gitlab-CI deploy the web site. So, I published in my local and send files to server. I compare with diff command local publish folder and gitlab-ci publish folder. All dll are seem different. But I don't know why. I check my local dotnet version, it's latest of 3.1. My gitlab-ci.yml file below.

Also I'm using AWS configuration. I got the first error because of this configuration. I changed my aws dependency implementation. These are below too.

testdeploy:
    stage: deploy
    image: ubuntu:20.04
    script:
        - apt-get update
        - apt -y install wget
        - wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
        - dpkg -i packages-microsoft-prod.deb
        - apt-get update
        - apt-get install apt-transport-https
        - apt-get update
        - apt-get -y install dotnet-sdk-3.1
        - dotnet restore
        - apt-get update
        - "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
        - eval $(ssh-agent -s)
        - ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 -d)
        - mkdir -p ~/.ssh
        - chmod 700 ~/.ssh
        - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
        - dotnet publish --output release --configuration Release
        - ls release
        - scp -o StrictHostKeyChecking=no -r ./release/* $SERVER_ADDRESS:$TEST_WEB_FOLDER
        - ssh -o StrictHostKeyChecking=no $SERVER_ADDRESS 'cd /opt/docker && docker-compose build testwebsite'
        - ssh -o StrictHostKeyChecking=no $SERVER_ADDRESS 'cd /opt/docker && docker-compose up -d'

AWS before:

public static class AmazonS3ClientExtensions
{
    public static void AddAmazonS3Client(this IServiceCollection services, IConfiguration configuration)
    {
        var region = configuration["AWS:Region"];
        var awsOptions = configuration.GetAWSOptions();
        var chain = new CredentialProfileStoreChain();
        if (!chain.TryGetAWSCredentials(awsOptions.Profile, out var awsCredentials))
        {
            throw new SystemException("Unable to locate AWS credentials");
        }
        var regionEndPoint = RegionEndpoint.GetBySystemName(region);
        var client = new AmazonS3Client(awsCredentials.GetCredentials().AccessKey,
            awsCredentials.GetCredentials().SecretKey, regionEndPoint);
        services.AddSingleton<IAmazonS3>(client);
    }
}

on Startup.cs

service.AddAmazonS3Client(services,Configuration);

Error logs with old configuration:

[10:02:24 FTL] Host terminated unexpectedly
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.get_ReturnType()
   at Microsoft.AspNetCore.Hosting.StartupLoader.FindMethod(Type startupType, String methodName, String environmentName, Type returnType, Boolean required)
   at Microsoft.AspNetCore.Hosting.StartupLoader.HasConfigureServicesIServiceProviderDelegate(Type startupType, String environmentName)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at WingTalent.WebUI.Program.Main(String[] args) in /builds/ikarus-hr/wing-talent/WingTalent.WebUI/Program.cs:line 31

Execute managed assembly exit code: 0x1

I change AWS configure like that.

services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddAWSService<IAmazonS3>();

Error logs with new configuration:

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at MVCUI.Program.CreateHostBuilder(String[] args)
   at MVCUI.Program.Main(String[] args) in /builds/website/MVCUI/Program.cs:line 32
c#
.net-core
asp.net-core-mvc
gitlab-ci
aws-config
asked on Stack Overflow Feb 8, 2021 by Sinan Barut

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0