我有两个docker文件。一个允许我使用$ versionControlServer.QueryHistory查询TFS。第二个允许我使用tf.exe从服务器下拉代码来对Version.html文件进行修改并签入更改。我想要一个可以同时执行Query TFS和Modify code的docker文件。我在执行此操作时遇到问题。首先,一个docker文件使用microsoft / windowservercode:10.0.14393.1480,另一个使用microsoft / dotnet-framework:4.7.1
这是针对TFS进行查询的代码
FROM microsoft/windowsservercore:10.0.14393.1480
# Setup shell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Note: Add NuGet
RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\windows\nuget.exe" -UseBasicParsing
RUN Mkdir LoadClient
COPY powershell \LoadClient
这里是psm1文件,用于加载TFS程序集
Write-Host "Loading InstallTFSClient"
#Module location folder
$TFSClientRoot = "C:\TFSClient"
#where to put TFS Client OM files
$NugetFolder = "$TFSClientRoot\Nuget\"
$BinFolder = $("$TFSClientRoot\bin\")
# TFS Object Model Assembly Names
$vsCommon = "Microsoft.VisualStudio.Services.Common"
$commonName = "Microsoft.TeamFoundation.Common"
$clientName = "Microsoft.TeamFoundation.Client"
$VCClientName = "Microsoft.TeamFoundation.VersionControl.Client"
$WITClientName = "Microsoft.TeamFoundation.WorkItemTracking.Client"
$BuildClientName = "Microsoft.TeamFoundation.Build.Client"
$BuildCommonName = "Microsoft.TeamFoundation.Build.Common"
$Source = @"
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation.Client;
using System.Net;
public class ConnectByImplementingCredentialsProvider : ICredentialsProvider
{
public ICredentials GetCredentials(Uri uri, ICredentials iCredentials)
{
return new NetworkCredential("OurUser", "OurPassword", "OurEnv");
}
public void NotifyCredentialsAuthenticated(Uri uri)
{
throw new ApplicationException("Unable to authenticate");
}
}
"@
#============================================================================
# new folder method
#============================================================================
function New-Folder{
param( [Parameter( Mandatory=$true)] $folderPath
)
if (Test-Path( $folderPath ))
{
Remove-Item $folderPath -Force -Recurse
}
mkdir $folderPath
}
#============================================================================
# Get-TfsAssembliesFromNuget method
#============================================================================
function Get-TfsAssembliesWithNuget{
New-Folder $TFSClientRoot
New-Folder $NugetFolder
New-Folder $BinFolder
#get all of the TFS 2015 Object Model packages from nuget
C:\windows\nuget install "Microsoft.TeamFoundationServer.Client" -Version 14.83.0 -OutputDirectory $NugetFolder -ExcludeVersion -NonInteractive
C:\windows\nuget install "Microsoft.TeamFoundationServer.ExtendedClient" -Version 14.83.0 -OutputDirectory $NugetFolder -ExcludeVersion -NonInteractive
C:\windows\nuget install "Microsoft.VisualStudio.Services.Client" -Version 14.83.0 -OutputDirectory $NugetFolder -ExcludeVersion -NonInteractive
C:\windows\nuget install "Microsoft.VisualStudio.Services.InteractiveClient" -Version 14.83.0 -OutputDirectory $NugetFolder -ExcludeVersion -NonInteractive
#Copy all of the required .dlls out of the nuget folder structure
#to a bin folder so we can reference them easily and they are co-located
#so that they can find each other as necessary when loading
$allDlls = Get-ChildItem -Path $NugetFolder -Recurse -File -Filter "*.dll"
# Create list of all the required .dlls
#exclude portable dlls
#$net45Dlls = $allDlls | ? {$_.PSPath.Contains("portable") -ne $true } | ? {$_.PSPath.Contains("resources") -ne $true } | ? { ($_.PSPath.Contains("net45") -eq $true) -or ($_.PSPath.Contains("native") -eq $true) -or ($_.PSPath.Contains("Microsoft.ServiceBus") -eq $true) }
$requiredDlls = $allDlls | Where-Object {$_.PSPath.Contains("portable") -ne $true } | where-object {$_.PSPath.Contains("resources") -ne $true } | where-object { ($_.PSPath.Contains("net45") -eq $true) -or ($_.PSPath.Contains("native") -eq $true) -or ($_.PSPath.Contains("Microsoft.ServiceBus") -eq $true) }
#exclude resource dlls
$requiredDlls = $requiredDlls | Where-Object {$_.PSPath.Contains("resources") -ne $true }
#include net45, native, and Microsoft.ServiceBus.dll
$requiredDlls = $requiredDlls | Where-Object { ($_.PSPath.Contains("net45") -eq $true) -or ($_.PSPath.Contains("native") -eq $true) -or ($_.PSPath.Contains("Microsoft.ServiceBus") -eq $true) }
#copy them all to a bin folder
$requiredDlls | ForEach-Object { Copy-Item -Path $_.Fullname -Destination $BinFolder}
}
#============================================================================
# Install-TfsAssembliesFromDisk method
#============================================================================
function Install-TfsAssembliesFromDisk{
Write-Host "loading TFS assemblies"
$TestVar = $($BinFolder + $vsCommon + ".dll")
write-host $TestVar
try {
Add-Type -LiteralPath $($BinFolder + $vsCommon + ".dll")
Add-Type -LiteralPath $($BinFolder + $commonName + ".dll")
Add-Type -LiteralPath $($BinFolder + $clientName + ".dll")
Add-Type -LiteralPath $($BinFolder + $clientName + ".dll")
$Assem = ("Microsoft.TeamFoundation.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp
Add-Type -LiteralPath $($BinFolder + $VCClientName + ".dll")
Add-Type -LiteralPath $($BinFolder + $WITClientName + ".dll")
Add-Type -LiteralPath $($BinFolder + $BuildClientName + ".dll")
Add-Type -LiteralPath $($BinFolder + $BuildCommonName + ".dll")
}
catch {
$_.Exception.LoaderExceptions | ForEach-Object { $_.Message }
}
}
Get-TfsAssembliesWithNuget
Install-TfsAssembliesFromDisk here
这是需要在容器上运行以激活所有内容的Powershell。
#============================================================================
# Setup TFS stuff
#============================================================================
function Setup-Tfs {
# Get TFS nuget packages installed
Import-Module C:\LoadClient\InstallTFSClient.psm1
# Connect to TFS
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client") | out-null
$tfsServer = "http://OurUrl:Port/etc...";
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer, (New-Object ConnectByImplementingCredentialsProvider))
$Script:versionControlServer = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer] )
$Script:recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
}
这是要加载tf.exe的Docker文件
# escape=`
# Use the latest Windows Server Core image with .NET Framework 4.7.1.
FROM microsoft/dotnet-framework:4.7.1
# Download the Build Tools bootstrapper.
ADD https://aka.ms/vs/15/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
# Install Build Tools excluding workloads and components with known issues.
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
--installPath C:\BuildTools `
--all `
--remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
--remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
--remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
--remove Microsoft.VisualStudio.Component.Windows81SDK `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
# Start developer command prompt with any other commands specified.
ENTRYPOINT C:\BuildTools\Common7\Tools\VsDevCmd.bat
# Default to PowerShell if no other command specified.
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
任何将其保存到一个docker文件的帮助都将得到极大的帮助。