dotnet / dotnet/msbuild

Add msbuild /restoresdks command line switch

Open
#2,992 1 comment 1 reaction 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

When building repository on CI server it is desirable that the script that bootstraps the repository is as small as possible and the core of the CI build logic is contained in a toolset nuget package.

The bootstrapper then needs to
1) install dotnet SDK
2) restore the toolset package
3) run msbuild on a proj file in the restored toolset package, which implements the CI build logic

This toolset package can be an SDK package, which has other benefits to the repository.
There is currently no straightforward way to restore the toolset package on CI server though.

The CI infrastructure might require additional steps to be performed before any solution in the repo can be restored. Therefore it is not feasible to trigger the SDK restore by restoring the solution itself.

We propose a `/restoresdks` command added to `msbuild` that restores the SDKs listed in `global.json` located in or above the current directory.

Currently we work around the lack of this command by the following PowerShell script:

```
$proj = Join-Path $TempDir "_restore.proj"
'' | Set-Content $proj
& dotnet msbuild $proj /t:NoOp /p:NuGetPackageRoot=$NuGetPackageRoot /p:__ExcludeSdkImports=true
```

The `__ExcludeSdkImports` property indicates to the SDK package that it shall not import any props and targets files from its `sdk\Sdk.props` and `sdk\Sdk.targets`. This is necessary since the targets might have some requirements on the project they are imported too that the dummy restore project doesn't meet.

It would also be useful to be able to find out from the script where the toolset was restored. Since a custom SDK resolver can be involved in the process we can't assume it's restored to nuget package cache.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the msbuild command-line entry point and the SDK restore behavior described around global.json; compare it with the PowerShell bootstrap workaround shown in the issue. Completion should cover restoring SDKs from global.json without restoring a solution and provide a way for the script to locate the restored toolset, including custom SDK resolver cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
build-system, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.