Skip to content

Commit c724554

Browse files
pwsh via dotnet tool (dotnet#4134)
Co-authored-by: Paul Medynski <31868385+paulmedynski@users.noreply.github.com>
1 parent ed896eb commit c724554

9 files changed

Lines changed: 77 additions & 18 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272
uses: actions/setup-dotnet@v5.2.0
7373
with:
7474
global-json-file: global.json
75+
76+
- name: Restore dotnet tools
77+
shell: bash
78+
run: dotnet tool restore
7579

7680
# Initializes the CodeQL tools for scanning.
7781
- name: Initialize CodeQL

BUILDGUIDE.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ on operating systems that do not support .NET Framework. As such, it is not nece
1919

2020
### Miscellaneous
2121

22-
**PowerShell** is required to run several miscellaneous tasks as part of building and packaging. On
23-
Windows systems, either the built-in `powershell.exe` will be used, or if installed, the modern
24-
`pwsh` will be used. On Linux and macOS systems, the `pwsh` command is required to be in the `$PATH`
25-
environment variable. For specific instructions see: [Install
26-
PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell)
22+
**PowerShell** is included as a .NET local tool in this repository. Running `dotnet tool restore`
23+
(see below) will make it available via `dotnet tool run pwsh -- <args>`. Note that `pwsh` is not
24+
added to PATH — it must be invoked through `dotnet tool run`. Build targets handle this
25+
automatically; manual invocation is only needed for ad-hoc scripting.
2726

2827
The **NuGet** binary is optional for inspection and feed-management workflows, but build and packaging flows in this
2928
repository are run through `dotnet build` against `build.proj`.
3029

30+
### .NET Tools
31+
32+
This repository uses .NET local tools (e.g. PowerShell) that must be restored before building. Run the following from the repository root:
33+
34+
```bash
35+
dotnet tool restore
36+
```
37+
3138
## Developer Workflow
3239

3340
Once you've cloned the repository and made your changes to the codebase, it is time to build, test, and optionally

dotnet-tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
"apicompat"
1616
],
1717
"rollForward": false
18+
},
19+
"powershell": {
20+
"version": "7.6.0",
21+
"commands": [
22+
"pwsh"
23+
],
24+
"rollForward": false
1825
}
1926
}
2027
}

eng/pipelines/common/templates/jobs/ci-build-nugets-job.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ jobs:
134134
# Install the .NET SDK.
135135
- template: /eng/pipelines/steps/install-dotnet.yml@self
136136

137+
# Restore dotnet CLI tools (e.g. pwsh, apicompat) before building.
138+
- template: /eng/pipelines/steps/restore-dotnet-tools.yml@self
139+
137140
# When we're performing a Debug build, we still want to try _compiling_ the
138141
# code in Release mode to ensure downstream pipelines don't encounter
139142
# compilation errors. We won't use the Release artifacts for anything else

eng/pipelines/common/templates/jobs/ci-run-tests-job.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ jobs:
222222
${{ else }}:
223223
runtimes: [8.x, 9.x]
224224

225+
# Restore dotnet CLI tools (e.g. pwsh, apicompat) before building.
226+
- template: /eng/pipelines/steps/restore-dotnet-tools.yml@self
227+
225228
- ${{ if ne(parameters.prebuildSteps, '') }}:
226229
- ${{ parameters.prebuildSteps }} # extra steps to run before the build like downloading sni and the required configuration
227230

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#################################################################################
2+
# Licensed to the .NET Foundation under one or more agreements. #
3+
# The .NET Foundation licenses this file to you under the MIT license. #
4+
# See the LICENSE file in the project root for more information. #
5+
#################################################################################
6+
7+
# Restores dotnet CLI tools defined in dotnet-tools.json.
8+
# This step should be invoked after install-dotnet.yml and before any build
9+
# steps that depend on the restored tools (e.g. pwsh, apicompat).
10+
11+
steps:
12+
- script: dotnet tool restore
13+
displayName: Restore .NET Tools
14+
workingDirectory: $(Build.SourcesDirectory)

src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,35 @@
4444
<OutputPath>$(ArtifactPath)$(AssemblyName).ref/$(ReferenceType)-$(Configuration)/</OutputPath>
4545
</PropertyGroup>
4646

47+
4748
<!-- Trim Docs for IntelliSense ====================================== -->
4849
<!--
4950
It has been determined that including the remarks section in IntelliSense docs looks bad in
5051
Visual Studio. So, before we generate the ref binaries, we trim off the remarks tags. We leave
5152
them in the xml files, though, because those are the source for the docs site, which needs to
5253
have the full documentation.
5354
-->
55+
<!-- Verifies that dotnet local tools have been restored (pwsh is required for doc trimming). -->
56+
<Target Name="_CheckPwshToolRestored">
57+
<Exec Command="dotnet tool run pwsh -- -Version"
58+
WorkingDirectory="$(RepoRoot)"
59+
ConsoleToMsBuild="true"
60+
IgnoreExitCode="true">
61+
<Output TaskParameter="ExitCode" PropertyName="_PwshExitCode" />
62+
</Exec>
63+
<Error Condition="'$(_PwshExitCode)' != '0'"
64+
Text="The 'pwsh' dotnet local tool is not available. Run 'dotnet tool restore' from the repository root before building." />
65+
</Target>
66+
5467
<!-- This target runs after Build, and trims XML documentation generated in the $(OutputPath) of the project where this target is included.-->
5568
<Target Name="TrimDocsForIntelliSense"
5669
AfterTargets="Build"
70+
DependsOnTargets="_CheckPwshToolRestored"
5771
Condition="'$(IsCrossTargetingBuild)' != 'true' AND '$(GenerateDocumentationFile)' == 'true'">
5872

5973
<PropertyGroup>
60-
<PowerShellCommand Condition="'$(OS)' == 'Windows_NT'">powershell.exe</PowerShellCommand>
61-
<PowerShellCommand Condition="'$(OS)' != 'Windows_NT'">pwsh</PowerShellCommand>
6274
<PowerShellCommand>
63-
$(PowerShellCommand)
75+
dotnet tool run pwsh --
6476
-NonInteractive
6577
-ExecutionPolicy Unrestricted
6678
-Command "$(RepoRoot)tools\intellisense\TrimDocs.ps1 -inputFile '$(DocumentationFile)' -outputFile '$(DocumentationFile)'"

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void SimpleFillTest()
107107

108108
// TODO Synapse: Remove Northwind dependency by creating required tables in setup.
109109
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
110+
// https://github.com/dotnet/SqlClient/issues/4135
111+
[Trait("Category", "flaky")]
110112
public void FillShouldAllowRetryLogicProviderToBeInvoked()
111113
{
112114
int maxRetries = 3;

tools/targets/CompareMdsRefAssemblies.targets

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,24 @@
5959
Text="BaselinePackageVersion is required. Specify the published MDS NuGet package version to compare against, e.g.: /p:BaselinePackageVersion=6.1.4" />
6060
</Target>
6161

62+
<!-- ================================================================== -->
63+
<!-- _CheckApiCompatToolRestored -->
64+
<!-- ================================================================== -->
65+
<Target Name="_CheckApiCompatToolRestored">
66+
<Exec Command="dotnet tool run apicompat -- --version"
67+
WorkingDirectory="$(RepoRoot)"
68+
ConsoleToMsBuild="true"
69+
IgnoreExitCode="true">
70+
<Output TaskParameter="ExitCode" PropertyName="_ApiCompatExitCode" />
71+
</Exec>
72+
<Error Condition="'$(_ApiCompatExitCode)' != '0'"
73+
Text="The 'apicompat' dotnet local tool is not available. Run 'dotnet tool restore' from the repository root before running this target." />
74+
</Target>
75+
6276
<!-- ================================================================== -->
6377
<!-- _DownloadBaselinePackage -->
6478
<!-- ================================================================== -->
65-
<Target Name="_DownloadBaselinePackage" DependsOnTargets="_ValidateBaselineVersion;_SetApiCompatProperties">
79+
<Target Name="_DownloadBaselinePackage" DependsOnTargets="_ValidateBaselineVersion;_CheckApiCompatToolRestored;_SetApiCompatProperties">
6680
<!-- Skip download if already extracted -->
6781
<Message
6882
Condition="Exists('$(BaselineExtractDir)')"
@@ -90,13 +104,6 @@
90104
Text="Baseline ref assemblies available at $(BaselineExtractDir)ref\" />
91105
</Target>
92106

93-
<!-- ================================================================== -->
94-
<!-- _RestoreTools -->
95-
<!-- ================================================================== -->
96-
<Target Name="_RestoreTools" DependsOnTargets="_SetApiCompatProperties">
97-
<Exec Command="dotnet tool restore" WorkingDirectory="$(RepoRoot)" />
98-
</Target>
99-
100107
<!-- ================================================================== -->
101108
<!-- _BuildRefProject -->
102109
<!-- ================================================================== -->
@@ -111,7 +118,7 @@
111118
<!-- _RunRefApiCompat -->
112119
<!-- ================================================================== -->
113120
<Target Name="_RunRefApiCompat"
114-
DependsOnTargets="_DownloadBaselinePackage;_RestoreTools;_BuildRefProject">
121+
DependsOnTargets="_DownloadBaselinePackage;_BuildRefProject">
115122

116123
<!--
117124
For each TFM, compare the consolidated ref output against the baseline
@@ -134,7 +141,7 @@
134141
Text="--- Comparing %(_RefTfm.Identity) ref vs baseline $(BaselinePackageVersion) ---" />
135142

136143
<Exec
137-
Command="dotnet apicompat -l &quot;$(BaselineExtractDir)ref/%(_RefTfm.Identity)/Microsoft.Data.SqlClient.dll&quot; -r &quot;$(RefOutputDir)%(_RefTfm.Identity)/Microsoft.Data.SqlClient.dll&quot; --strict-mode &gt; &quot;$(ApiCompatResultsDir)%(_RefTfm.Identity).txt&quot; 2&gt;&amp;1"
144+
Command="dotnet tool run apicompat -- -l &quot;$(BaselineExtractDir)ref/%(_RefTfm.Identity)/Microsoft.Data.SqlClient.dll&quot; -r &quot;$(RefOutputDir)%(_RefTfm.Identity)/Microsoft.Data.SqlClient.dll&quot; --strict-mode &gt; &quot;$(ApiCompatResultsDir)%(_RefTfm.Identity).txt&quot; 2&gt;&amp;1"
138145
WorkingDirectory="$(RepoRoot)"
139146
ContinueOnError="ErrorAndContinue" />
140147

0 commit comments

Comments
 (0)