I have a VS solution that uses the container orchestrator feature to allow VS to integrate docker-compose functionality. Building the solution in release or debug on a windows machine using WSL2 and Docker Desktop works great. I can just build and run the solution (release or debug) through VS. Now I wish to set up a Azure Pipeline and can't figure out the best way to build the solution. I wish to continue targeting Linux for deployment, but the VSBuild@1 task in Azure Pipelines is not capable of running on Linux machines. Should I build each Dockerfile separately in the pipeline?
The solution is made up of multiple projects with most project having three references to other projects. Visual Studio generates Dockerfiles for each project to allow these projects to build correctly. For example one of the dockerfiles:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["SynchronizationManager/SynchronizationManager.csproj", "SynchronizationManager/"]
COPY ["EventbusConfig/EventbusConfig.csproj", "EventbusConfig/"]
COPY ["MessagingContracts/MessagingContracts.csproj", "MessagingContracts/"]
COPY ["SynchronizationDomain/SynchronizationDomain.csproj", "SynchronizationDomain/"]
RUN dotnet restore "SynchronizationManager/SynchronizationManager.csproj"
COPY . .
WORKDIR "/src/SynchronizationManager"
RUN dotnet build "SynchronizationManager.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SynchronizationManager.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SynchronizationManager.dll"]
As you can see, the Dockerfile expects other projects to be in a certain location. How can I build the other projects on ubuntu-latest and place them in the correct location so that the Dockerfiles don't fail?
The pipeline in its current form:
pool:
vmImage: 'ubuntu-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:langversion=latest /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
I ended up using DotNetCli commands to build and test:
pool:
vmImage: 'ubuntu-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: UseDotNet@2
displayName: 'Install .Net SDK 7'
inputs:
packageType: 'sdk'
version: '7.x'
- task: DotNetCoreCLI@2
displayName: Build solution
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Run tests
inputs:
command: test
arguments: '--configuration $(buildConfiguration)'
projects: '**/*.Test.csproj'
publishTestResults: true