0
votes

I'm busy creating a Azure Devops build pipeline for a ASP.NET MVC application, but I'm stuck on restoring some NuGet packages.

I decided to add all folders to the .gitignore file that are added by NuGet package installs. Because pipelines will reproduce this files when doing a NuGet restore.

Unfortunately , for one of my installed NuGet-packages this doesn't work: the expected files were not added to my artifact.

When I install this package manually in Visual Studio, NuGet will add an assembly and some files inside the App_Plugins/uSync folder, but the NuGet restore step in Pipelines does not: it only added the assembly to the final artifact. The App_Plugins files are missing.

Below my YAML representation of the build pipeline:

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'artifact'
    publishLocation: 'Container'

Any help much appreciated!

1
With packages.config, there is a difference between restore and install. When you install, it is allowed to modify the project, including copying files from the package into the project folder. With restore, NuGet does not modify the project, it only downloads the nupkg and extracts the zip in the packages folder. install only works in Visual Studio, as NuGet asks Visual Studio's project systems to modify the project files (csproj, vbproj and so on). So, you need to check in those files as long as you keep using packages.config.zivkan
Ah, that make sense! Is there a way to do this in Pipelines instead of checking in the required files? And.. with your explanation I would expect this behavior applied to all my NuGet packages, but some of my packages are correctly added to the artifact: assemblies AND solution files.Corné Strijkert
If you look at your project file (csproj) after installing a new package (if you use a source control system, you can look at the diff), you'll see that it gets a <Reference element that points to the assemblies in the solution packages folder. So, NuGet isn't restoring anything INTO your project, it's restoring only into the packages folder. The project is configured to consume those files from the packages folder. You can try yourself. git clean to delete all your bin and packages folders. Do a NuGet restore locally. See there are still no bin folders.zivkan
While you would like the packages content files to be copied into the project directory on restore, content files are often used to populate configuration file defaults, which are then modified (either contents, or names changed, deleted, etc). If NuGet restore recreated them, those modifications would be lost. So, while it could work in your use case, it is genuinely problematic in others. Plus, with non-SDK style projects, the csproj needs to be modified to have <Content Include="filename.ext" />. NuGet doesn't know how to do that, but in VS when you install, NuGet tells VS to do it.zivkan
For these types of reasons, ASP.NET Core projects no longer bring web development assets (js, css) via NuGet packages. The recommendation is to use npm or libman. I no longer do web development, so I don't know how easy it is to integrate these tools into a non-core ASP.NET project.zivkan

1 Answers

0
votes

Just curious, what NuGet version is used in your build pipeline.As per doc, This version of the NuGet task uses NuGet 4.1.0 by default. To select a different version of NuGet, use the Tool Installer.