How to import one repository's .targets file in another repository in gitlab?

Viewed 519

I have a repository product-config in gitlab that contains settings/configurations that are shared by the rest of the repositories.

So for e.g. I have a repository ec-firmware-service which has .productConfiguration.targets file which imports .target file of product-config repository like this

 <Import Project="$(MSBuildThisFileDirectory)..\..\product-config\.msbuild\TransformApplicationConfig.targets" />
 <Import Project="$(MSBuildThisFileDirectory)..\..\product-config\.msbuild\TaskConfigPreprocessor.targets" />

And product-config repository does have these target files but I am still getting this build error

C:\builds\engineering\myproject\swc\ec-firmware-service\Configuration\\.productConfiguration.targets(5,3):
error MSB4019: The imported project
"C:\builds\engineering\myproject\swc\product-config\\.msbuild\TransformApplicationConfig.targets"
was not found. Confirm that the expression in the Import declaration
"C:\builds\engineering\myproject\swc\ec-firmware-service\Configuration\\..\\..\product-config\\.msbuild\TransformApplicationConfig.targets"
is correct, and that the file exists on disk.
[C:\builds\engineering\myproject\swc\ec-firmware-service\src\EC.FirmwareService.WebApi\EC.FirmwareService.WebApi.csproj]

So basically it is this error

The imported project "C:\builds\engineering\myproject\swc\product-config\.msbuild\TransformApplicationConfig.targets" was not found.

Which is correct directory and path to the TransformApplicationConfig.targets file but it is somehow not able to pick it up.

The only reason that I can see is because it is in different repository.

Is there any way to target files in different repositories in gitlab or what could be the solution?

Update

I am targeting to build .net framework solution using this docker image in my .gitlab-ci.yml file mcr.microsoft.com/dotnet/framework/sdk

One solution that was suggested is to clone the repository to the current repository while building the solution so I tried to do that but the docker image I am using does not include git and so could not follow that solution.

So this is what I have written in my gitlab file

# Build
Build:
  stage: build
  image: mcr.microsoft.com/dotnet/framework/sdk
  before_script:
    #- git 
  script:
    - echo $URL
    - cd src
    #- git clone https://${productconfigdeployerusername}:${productconfigdeployerpassword}@gitlab.cpicloudservices.com/engineering/easitrax-connect/swc/product-config.git
    - msbuild /t:restore
    - msbuild EC.FirmwareService.sln /p:Configuration=Release
  only:
    - branches
  tags:
    - windows-runner
  environment:
    name: development

You can see the git clone line is commented. If I uncomment it, it starts giving error that git is not recognized.

1 Answers

You could try creating a new image and install git there, but I have no idea how one would do that in windows.

Instead, you could add a separate job that clones the repository, and exports it as a job artifact. This artifact can then be used by the windows job, removing the need for git in the image.

stages:
  - pre-build
  - build

# Build
Clone:
  stage: pre-build
  image: alpine/git
  script:
    - mkdir git
    - cd git
    - git clone https://${productconfigdeployerusername}:${productconfigdeployerpassword}@gitlab.cpicloudservices.com/engineering/easitrax-connect/swc/product-config.git
  artifacts:
    paths:
      - src
    expire_in: 1 day
  needs: []
  only:
    - branches

Build:
  stage: build
  image: mcr.microsoft.com/dotnet/framework/sdk 
  script:
    - echo $URL
    - cd src
    - msbuild /t:restore
    - msbuild EC.FirmwareService.sln /p:Configuration=Release
  only:
    - branches
  tags:
    - windows-runner
  environment:
    name: development
  needs: ["Clone"]

Disclaimer: I did not run this code, it could contain errors.

Related