2

According to MSDocs here, there is a task to publish .NET Core with arguments.

dotnet publish --output $(Build.ArtifactStagingDirectory)

But I have a .NET Framework application, not .NET Core, which means i use MSBuild task not dotnetcore task to build .NET. so i checked out the .NET Framework page and there's literally no information about publishing .NET Framework app...

Does this mean that the same dotnetcore tasks apply/can be used for .NET Framework app then??

steps:

- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
    artifactName: 'myWebsiteName'
Cataster
  • 3,081
  • 5
  • 32
  • 79
  • Once you install VS on Windows, the publishing related tasks are in the `Microsoft.WebApplication.targets` under VS installation folder. You can review it to learn what are the tasks you might utilize for .NET Framework based web apps. However, you won't get them on a Linux build agent machine, as there is no VS/.NET Framework for Linux. – Lex Li Mar 25 '21 at 15:50
  • @LexLi the reason i am using linux/ubuntu agent is because the build time is 3 minutes compared to 10 mins on windows agent. I had to edit my csproj file and packages.config to remove .NET Compiler, convert the PackageReference to packages.config, and add `` to packages.config which finally made the MSBuild work on the Ubuntu agent successfully. The build is working, I just need to publish the "Release" artifact to consume it in the release pipeline. – Cataster Mar 25 '21 at 16:01
  • A .NET Framework based application is only fully supported on Windows (compilation as well as deployment), so hacking MSBuild like that on Linux isn't really "working". – Lex Li Mar 25 '21 at 16:06
  • @LexLi thats what i thought too, but Lance helped me out here and after some tweaks I was able to get the same exact result as that when running on windows. https://developercommunity.visualstudio.com/t/Why-%E2%80%9CCould-not-locate-the-assembly-%E2%80%9DSyst/1296528 – Cataster Mar 25 '21 at 16:09
  • @LexLi ok i just tried something simple, all i did is Archive `projectname/obj/Release` as root folder or file to archive and for "Archive File to Create" I specified `$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip`, and finally in publish task i just specified `$(Build.ArtifactStagingDirectory)` for Path to Publish and i was able to get an artifact created – Cataster Mar 25 '21 at 17:13

2 Answers2

2

The following build works on the ubuntu build agent:

enter image description here

The yaml definition:

steps:

- task: NuGetToolInstaller@1    
  displayName: 'Use NuGet '    

- task: NuGetCommand@2    
  displayName: 'NuGet restore'    
  inputs:    
    restoreSolution: '<my_path>.sln'    

- task: MSBuild@1    
  displayName: 'Build solution <my_path>.sln'    
  inputs:    
    solution: '<my_path>.sln'    
    platform: '$(BuildPlatform)'    
    configuration: '$(BuildConfiguration)'    

- task: CopyFiles@2    
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'    
  inputs:    
    SourceFolder: '$(system.defaultworkingdirectory)'    
    Contents: '**/bin/**'    
    TargetFolder: '$(build.artifactstagingdirectory)'    
  condition: succeededOrFailed()
       
- task: PublishBuildArtifacts@1    
  displayName: 'Publish Artifact: drop'    
  inputs:    
    PathtoPublish: '$(build.artifactstagingdirectory)'    
  condition: succeededOrFailed()
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
  • 1
    I cant use VSBuild because I am running this on Ubuntu agent which doesnt have VS, tahts why i am using MSBuild – Cataster Mar 25 '21 at 14:40
  • Btw Ive tried this with MSBuild and it said there was 0 files to copy even though the build finished successfully... – Cataster Mar 25 '21 at 16:59
  • @Cataster, I've tested with the classic pipeline and it works, check the yaml on my updated answer.... try to copy `Contents: '**/bin/**'` – Shamrai Aleksander Mar 25 '21 at 18:25
  • Can you show me the classic pipeline images of the tasks? I would prefer to do this in classic pipeline anyways :) – Cataster Mar 25 '21 at 18:32
  • ok so i changed `Contents: '**\bin\$(BuildConfiguration)\**'` to `**/bin/**'` and that seemed to have done the rick! 250 files were copied :) – Cataster Mar 25 '21 at 18:43
  • @Cataster You can use `**/bin/$(BuildConfiguration)/**` but check that `BuildConfiguration` variable contains `Release` instead of `release`. – Shamrai Aleksander Mar 25 '21 at 19:09
  • nope that resulted in 0 files once again, changing it back to `**/bin/**` resulted in 250 files – Cataster Mar 25 '21 at 20:46
  • ok so i checked with the developer and he said some of the folders like views that usually get created when he builds locally are missing. so instead of `**/bin/**` i specified `**/**` and 69k files were generated, including angular node_modules which were also included in the 250 files and the developer said he doesnt want those to be included in the artifact used for deployment. How do I include like the AngularOutput and Views and exclude everything else? was it using an exclamation mark? `!` – Cataster Mar 25 '21 at 21:43
  • @Cataster, I do not work with Angular. You can build your solution locally and check with developers which files they need, and then can try to adjust the `Contents`. Or create a new thread "How to build angular with MSBuild" ))). Check this link: https://byalexblog.net/using-msbuild-to-deploy-composite-web-application – Shamrai Aleksander Mar 26 '21 at 09:07
  • The publish action for an ASP.NET application doesn't just copy from the bin folder, or copy everything... – Rye bread Aug 01 '22 at 10:47
1

dotnet publish / DotNetCoreCLI@2 publish task only works for .NET Core and above.

If you append the following parameters it will perform a Publish as part of a build using the VSBuild task. It may also work with the MSBuild task, I have not tried that.

Parameters to add for an ASP.NET (.NET Framework) web application:

'/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)/Build/"'

VSBuild task:

- task: VSBuild@1
  inputs:
    solution: $(solutionFileName)    
    vsVersion: ${{ parameters.visualStudioVersion }}
    platform: '${{ parameters.platform }}'
    configuration: 'Release' 
    msbuildArgs: '$(msBuildArgs)'

The packaged .zip will be found in $(Build.ArtifactStagingDirectory)/Build/.

Rye bread
  • 1,305
  • 2
  • 13
  • 36