0
votes

I have an issue on Azure DevOps only!

It works fine in Visual Studio 2019, when I right click and Build. It also works fine if I use dotnet build from a CMD, locally.

Nuget package looks like this:

csproj

 <ItemGroup>
    <None Include="Utilities.Api.xml" Pack="true" PackagePath="File">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="build\Utilities.Api.props" Pack="true" PackagePath="build"></None>

  </ItemGroup>

  <ItemGroup>
    <None Update="Utilities.Api.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>


    </None>
  </ItemGroup>

props file

<Project>

    <Target Name="CopyFilesToProject" BeforeTargets="Build">
        <ItemGroup>
            <SourceScripts Include="$(MSBuildThisFileDirectory)..\File\*.xml*"/> 
        </ItemGroup>
        <Copy
           SourceFiles="@(SourceScripts)"
           DestinationFolder="$(OutDir)"
        />
    </Target>


</Project>

When I run the pipeline on Azure I use this version of MSBuild (Microsoft (R) Build Engine version (16.7.0+7fb82e5b2 for .NET) via "dotnet build".

pipeline build step:

  - task: DotNetCoreCLI@2
    displayName: Build
    timeoutInMinutes: 0
    inputs:
      command: build
      projects: src/**/*.csproj
      arguments: '--configuration $(BuildConfiguration) /p:reportanalyzer=true /p:TreatWarningsAsErros=$(warnAsErrors)'

I have a publish step after my build.

 - task: DotNetCoreCLI@2
    condition: and(succeeded(), not(variables.RunSonar))
    displayName: Publish and zip artifacts
    inputs:
      command: publish
      publishWebProjects: false
      arguments: '--configuration $(buildConfiguration) --no-build --output $(Build.ArtifactStagingDirectory)'
      packDirectory: '$(Build.ArtifactStagingDirectory)'
      zipAfterPublish: true
      projects: |
        src/**/*.Api.csproj
        !src/Test/**/*.csproj

This is beginning to be super frustrating :)

2
Did you try dotnet msbuild command docs.microsoft.com/en-us/dotnet/core/tools/dotnet-msbuild ? You need to use custom command in DotNetCoreCLI@2 task.Krzysztof Madej
Can you add logs of your Build step?Krzysztof Madej
Just the logs from azure devops you want to see ?Daniel Frost
yes, only form Azure DevOpsKrzysztof Madej

2 Answers

0
votes

The logs from Azure Devops Build step:

2020-10-01T08:49:43.2627436Z [command]C:\ag1\_w\_tool\dotnet\dotnet.exe build C:\ag1\_w\16\s\src\Users.Api\Users.Api.csproj "-dl:CentralLogger,\"C:\ag1\_w\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.175.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"C:\ag1\_w\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.175.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release /p:reportanalyzer=true /p:TreatWarningsAsErros=True
2020-10-01T08:49:43.6522165Z Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
2020-10-01T08:49:43.6522892Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-10-01T08:49:43.6523107Z 
2020-10-01T08:49:44.1610081Z   Determining projects to restore...
2020-10-01T08:49:44.7025130Z   All projects are up-to-date for restore.
2020-10-01T08:49:45.5019137Z   Users.DomainServices.Public -> C:\ag1\_w\16\s\src\Users.DomainServices.Public\bin\Release\netcoreapp3.1\barfoo.Users.DomainServices.Public.dll
2020-10-01T08:49:45.6746889Z   Users.Infrastructure.Public -> C:\ag1\_w\16\s\src\Users.Infrastructure.Public\bin\Release\netcoreapp3.1\barfoo.Users.Infrastructure.Public.dll
2020-10-01T08:49:45.8373672Z   Users.DomainServices -> C:\ag1\_w\16\s\src\Users.DomainServices\bin\Release\netcoreapp3.1\barfoo.Users.DomainServices.dll
2020-10-01T08:49:46.1381732Z   Users.Infrastructure -> C:\ag1\_w\16\s\src\Users.Infrastructure\bin\Release\netcoreapp3.1\barfoo.Users.Infrastructure.dll
2020-10-01T08:49:46.3793169Z   Users.Api -> C:\ag1\_w\16\s\src\Users.Api\bin\Release\netcoreapp3.1\barfoo.Users.Api.dll
2020-10-01T08:49:46.3979376Z 
2020-10-01T08:49:46.3980068Z Build succeeded.
2020-10-01T08:49:46.3980389Z     0 Warning(s)
2020-10-01T08:49:46.3981116Z     0 Error(s)
0
votes

Okay, I found the solution. Which makes sense.

The reason for this behavior was that I did only have targets for the BeforeBuild. I had to add a Target for the Publish too.

My props file now looks like this, and it works both locally and on Azure DevOps.

<Project>

  <Target Name="CopyFilesToProject" BeforeTargets="BeforeBuild">
    <ItemGroup>
      <SourceScripts Include="$(MSBuildThisFileDirectory)..\File\*.xml*"/>
    </ItemGroup>

    <Copy
         SourceFiles="@(SourceScripts)"
         DestinationFolder="$(OutDir)" />
  </Target>


  <Target Name="PublishCopyFiles" AfterTargets="Publish">
    <ItemGroup>
      <SourceScripts Include="$(MSBuildThisFileDirectory)..\File\*.xml*"/>
    </ItemGroup>
    <Copy
       SourceFiles="@(SourceScripts)"
       DestinationFolder="$(PublishDir)" />
  </Target>

</Project>