C
C#2y ago
redforce04

❔ [Compiler Help] [GitLab CI/CD]

I'm trying to replace some basic strings with important data about the git hash and git branch, and I am able to replace the strings but they are not actually building into the app. I am using gitlab ci/cd to build them for me, and I can see that the output definitely is changing however when I view the dll in my compiler (DnSpy), the strings are not updated. I am using the official dotnet ci cd file with some modifications.
2 Replies
redforce04
redforce04OP2y ago
I want to update these right before compilation because one of the apps is dotnet 7.0 native aot and since it doesn't have reflection, I need a simpler solution The other app is dotnet framework 4.8.1 Here is my gitlab ci cd file (mostly stripped of comments):
image: redforce04/discordbot:netdataslbuilder
stages:
- build

variables:
OBJECTS_DIRECTORY: 'obj'
NUGET_PACKAGES_DIRECTORY: '.nuget'
SOURCE_CODE_PATH: '*/'

cache:
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json'
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.*'
- '$NUGET_PACKAGES_DIRECTORY'
policy: pull-push

before_script:
- 'dotnet restore --packages $NUGET_PACKAGES_DIRECTORY'

build:
stage: build
script:
- 'envsubst < PWProfiler/AssemblyInfo.cs | sponge PWProfiler/AssemblyInfo.cs'
- 'dotnet publish -c Release --no-restore'
- 'mv PWProfiler/bin/Debug/PWProfiler.dll PWProfiler.dll'
artifacts:
name: "Build Results"
paths:
- PWProfiler.dll

image: redforce04/discordbot:netdataslbuilder
stages:
- build

variables:
OBJECTS_DIRECTORY: 'obj'
NUGET_PACKAGES_DIRECTORY: '.nuget'
SOURCE_CODE_PATH: '*/'

cache:
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json'
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.*'
- '$NUGET_PACKAGES_DIRECTORY'
policy: pull-push

before_script:
- 'dotnet restore --packages $NUGET_PACKAGES_DIRECTORY'

build:
stage: build
script:
- 'envsubst < PWProfiler/AssemblyInfo.cs | sponge PWProfiler/AssemblyInfo.cs'
- 'dotnet publish -c Release --no-restore'
- 'mv PWProfiler/bin/Debug/PWProfiler.dll PWProfiler.dll'
artifacts:
name: "Build Results"
paths:
- PWProfiler.dll

I used cat to verify the file was updated, and it seemed to look fine I use envsubst < PWProfiler/AssemblyInfo.cs | sponge PWProfiler/AssemblyInfo.cs to replace the variable and overwrite it it basically overwrites this file:
public static class AssemblyInfo
{
public const string CommitHash = "${CI_COMMIT_SHORT_SHA}";
public const string CommitBranch = "${CI_COMMIT_BRANCH}";
}
public static class AssemblyInfo
{
public const string CommitHash = "${CI_COMMIT_SHORT_SHA}";
public const string CommitBranch = "${CI_COMMIT_BRANCH}";
}
here is the file after cat:
public static class AssemblyInfo
{
public const string CommitHash = "9cfd23c0";
public const string CommitBranch = "dev";
}
public static class AssemblyInfo
{
public const string CommitHash = "9cfd23c0";
public const string CommitBranch = "dev";
}
Accord
Accord2y ago
Looks like nothing has happened here. 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