I'm trying to set up an ADO pipeline that does the following:
The reasoning here is that we want to allow using packages we haven't approved yet except on official release builds, but want developers to know that they need to request approval.
I've set up two DotNetCoreCLI@2
tasks which I think should work:
- task: DotNetCoreCLI@2
displayName: "Restore using official sources"
continueOnError: true
inputs:
command: 'restore'
feedsToUse: 'config'
nugetConfigPath: '$(Agent.BuildDirectory)/templates/nuget.official.config'
noCache: true
- task: DotNetCoreCLI@2
displayName: "Restore using development sources"
inputs:
command: 'restore'
feedsToUse: 'config'
nugetConfigPath: '$(Agent.BuildDirectory)/templates/nuget.dev.config'
However, I'm finding this doesn't work in the oddest way - the second task uses the exact same config as the first. It seems the DotNetCoreCLI task decides it doesn't need to rewrite the config file.
Is there something I'm missing, or some other way to achieve what I'm trying to achieve?
It appears that the restore command in the DotNetCoreCli@2 task, uses a utility class to generate a temporary configuration file. The task is designed to delete the temporary config file after the task completes, but it looks like the utility class won't overwrite the config file if it already exists.
The name of the configuration file is deterministic:
private getTempNuGetConfigPath(): string {
const tempNuGetConfigBaseDir = NuGetConfigHelper2.getTempNuGetConfigBasePath();
const tempNuGetConfigFileName = "tempNuGet_" + tl.getVariable("build.buildId") + ".config";
return path.join(tempNuGetConfigBaseDir, "Nuget", tempNuGetConfigFileName);
}
public static getTempNuGetConfigBasePath() {
return tl.getVariable("Agent.BuildDirectory")
|| tl.getVariable("Agent.TempDirectory");
}
The file deletion process in nodejs varies by OS and could be subject to other factors. For example, a self-hosted build agent might have antivirus that prevents the file from being properly deleted. If using a self-hosted agent, try reproducing the build in a cloud-provided agent. If using ubuntu, try Windows.
You could in theory also try to delete the file between nuget restore operations.
variables:
tempNugetBasePath: $[ coalesce( variables['Agent.BuildDirectory'], variables['Agent.TempDirectory']) ]
tempNugetPath: $(tempNugetBasePath)/Nuget/tempNuget_$(Build.BuildId).config
steps:
- ... # nuget restore 1
- pwsh: |
if (Test-Path($env:tempNuget)) {
Write-Host ("Temporary nuget file path was not deleted: {0}" -f $env:tempNuget)
Remove-Item -Path $env:tempNuget -Force -ErrorAction SilentlyContinue
}
displayName: Delete nuget config
env:
tempNuget: $(tempNugetPath)
- ... # nuget restore 2