Restore IBCMerge using an authenticated service connection (#24284)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Mon, 29 Apr 2019 16:27:10 +0000 (09:27 -0700)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2019 16:27:10 +0000 (09:27 -0700)
* Add separate build steps to do the IBCMerge restore.

* Attempt 1 to get config picked up.

* Attempt 2 getting ibcmerge restore working.

* Fix invalid MSBuild syntax.

* Fix getting IBC package version.

build.cmd
eng/build-job.yml
eng/internal/NuGet.config [new file with mode: 0644]
src/.nuget/optdata/ibcmerge.csproj

index 3d9a27a..bd6d355 100644 (file)
--- a/build.cmd
+++ b/build.cmd
@@ -670,11 +670,7 @@ if %__BuildCoreLib% EQU 1 (
         for /f "tokens=*" %%s in ('call "%__ProjectDir%\dotnet.cmd" msbuild "!IbcMergeProjectFilePath!" /t:DumpIbcMergePackageVersion /nologo') do @(
             set __IbcMergeVersion=%%s
         )
-
-        echo Restoring IBCMerge version !__IbcMergeVersion!...
-        echo Running: %__ProjectDir%\dotnet.cmd restore src/.nuget/optdata/ibcmerge.csproj --no-cache --packages "%__PackagesDir%" --source "https://devdiv.pkgs.visualstudio.com/_packaging/dotnet-core-internal-tooling/nuget/v3/index.json"
-        call %__ProjectDir%\dotnet.cmd restore src/.nuget/optdata/ibcmerge.csproj --no-cache --packages "%__PackagesDir%" --source "https://devdiv.pkgs.visualstudio.com/_packaging/dotnet-core-internal-tooling/nuget/v3/index.json"
-
+  
         set IbcMergePath=%__PackagesDir%\microsoft.dotnet.ibcmerge\!__IbcMergeVersion!\tools\netcoreapp2.0\ibcmerge.dll
         if exist !IbcMergePath! (
             echo %__MsgPrefix%Optimizing using IBC training data
@@ -754,7 +750,7 @@ if %__BuildCoreLib% EQU 1 (
                 goto CrossgenFailure
             )
         ) else (
-          echo Could not find IBCMerge at !IbcMergePath!
+          echo Could not find IBCMerge at !IbcMergePath!. Have you restored src/.nuget/optdata/ibcmerge.csproj?
           goto CrossgenFailure
         )
     )
index d62d267..ec91ba0 100644 (file)
@@ -101,6 +101,26 @@ jobs:
       - script: eng\common\init-tools-native.cmd -InstallDirectory $(Build.SourcesDirectory)\native-tools -Force
         displayName: Install native dependencies
 
+    # Install internal tools on official builds
+    # Since our internal tools are behind an authenticated feed,
+    # we need to use the DotNetCli AzDO task to restore from the feed using a service connection.
+    # We can't do this from within the build, so we need to do this as a separate step.
+    - ${{ if and(and(eq(variables['System.TeamProject'], 'internal'), ne(variables['Build.Reason'], 'PullRequest')), eq(parameters.osGroup, 'Windows_NT')) }}:
+        - task: DotNetCoreInstaller@0
+          inputs:
+            packageType: 'sdk'
+            version: '2.1.503'
+        - task: DotNetCoreCLI@2
+          displayName: Restore internal tools
+          inputs:
+            command: restore
+            feedsToUse: config
+            projects: 'src/.nuget/optdata/ibcmerge.csproj'
+            nugetConfigPath: 'eng/internal/NuGet.config'
+            restoreDirectory: '$(Build.SourcesDirectory)\packages'
+            verbosityRestore: 'normal'
+            externalFeedCredentials: 'dotnet-core-internal-tooling'
+
     # Build
     - ${{ if ne(parameters.osGroup, 'Windows_NT') }}:
       - script: ./build.sh $(buildConfig) $(archType) $(crossArg) -skiptests -skipnuget $(clangArg) $(stripSymbolsArg) $(officialBuildIdArg)
diff --git a/eng/internal/NuGet.config b/eng/internal/NuGet.config
new file mode 100644 (file)
index 0000000..b7a79f1
--- /dev/null
@@ -0,0 +1,14 @@
+<configuration>
+  <!-- Don't use any higher level config files.
+       Our builds need to be isolated from user/machine state -->
+  <fallbackPackageFolders>
+    <clear />
+  </fallbackPackageFolders>
+  <packageSources>
+    <clear/>
+    <add key="dotnet-core-internal-tooling" value="https://devdiv.pkgs.visualstudio.com/_packaging/dotnet-core-internal-tooling/nuget/v3/index.json" />
+  </packageSources>
+  <disabledPackageSources>
+    <clear />
+  </disabledPackageSources>
+</configuration>
index e69ac17..3ec0272 100644 (file)
@@ -9,11 +9,16 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="microsoft.dotnet.ibcmerge" Version="$(IbcMergePackageVersion)" Condition="'$(IbcMergePackageVersion)'!=''" />
+    <PackageReference Include="microsoft.dotnet.ibcmerge" Version="[$(IbcMergePackageVersion)]" Condition="'$(IbcMergePackageVersion)'!=''" />
   </ItemGroup>
 
   <Target Name="DumpIbcMergePackageVersion">
     <Message Importance="high" Text="$(IbcMergePackageVersion)" />
   </Target>
 
+  <PropertyGroup>
+    <RestoreSources>
+      https://devdiv.pkgs.visualstudio.com/_packaging/dotnet-core-internal-tooling/nuget/v3/index.json;
+    </RestoreSources>
+  </PropertyGroup>
 </Project>