Skip to content

Commit 76fea14

Browse files
nohwndEvangelink
andauthored
Fix executable bitness for testhost.x86 (#4652) (#4654)
Co-authored-by: Amaury Levé <[email protected]>
1 parent c59bb29 commit 76fea14

File tree

6 files changed

+115
-2
lines changed

6 files changed

+115
-2
lines changed

azure-pipelines.yml

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ variables:
8787
- name: VisualStudioDropName
8888
value: Products/$(System.TeamProject)/$(Build.DefinitionName)/$(Build.SourceBranchName)/$(Build.BuildNumber)
8989
- name: _InternalBuildArgs
90+
# IncludeSourceRevisionInInformationalVersion prevents ProductVersion (on file), and AssemblyInformationalVersion
91+
# from appending +<commitId>, which breaks DTAAgent.
9092
value: /p:DotNetSignType=$(_SignType)
9193
/p:TeamName=$(_TeamName)
9294
/p:DotNetFinalVersionKind=$(_ReleaseVersionKind)
@@ -96,6 +98,7 @@ variables:
9698
/p:OfficialBuildId=$(BUILD.BUILDNUMBER)
9799
/p:VisualStudioDropName=$(VisualStudioDropName)
98100
/p:GenerateSbom=true
101+
/p:IncludeSourceRevisionInInformationalVersion=false
99102

100103
stages:
101104

@@ -152,9 +155,11 @@ stages:
152155
displayName: Build
153156

154157
# -ci is allowing to import some environment variables and some required configurations
158+
# -nobl avoid overwriting binlog of the main Build
155159
- script: Test.cmd
156160
-configuration $(_BuildConfig)
157161
-ci
162+
-nobl
158163
-integrationTest
159164
-performanceTest
160165
name: Test

eng/verify-nupkgs-exe-version.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Get-ChildItem S:\p\vstest3\artifacts\packages\Debug\Shipping -Filter vstest.console.exe -Recurse -Force | ForEach-Object {
2+
if ($_.VersionInfo.ProductVersion.Contains("+")) {
3+
throw "Some files contain '+' in the ProductVersion, this breaks DTAAgent in AzDO."
4+
}
5+
else {
6+
"$_ version $($_.VersionInfo.ProductVersion) is ok."
7+
}
8+
}

eng/verify-nupkgs-exe.ps1

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
$exclusions = @{
2+
"CodeCoverage\CodeCoverage.exe" = "x86"
3+
"Dynamic Code Coverage Tools\CodeCoverage.exe" = "x86"
4+
"amd64\CodeCoverage.exe" = "x64"
5+
6+
"IntelliTrace.exe" = "x86"
7+
"ProcessSnapshotCleanup.exe" = "x86-64"
8+
"TDEnvCleanup.exe" = "x86"
9+
10+
"TestPlatform\SettingsMigrator.exe" = "x86"
11+
12+
"dump\DumpMinitool.exe" = "x86-64"
13+
14+
"QTAgent32.exe" = "x86"
15+
"QTAgent32_35.exe" = "x86"
16+
"QTAgent32_40.exe" = "x86"
17+
"QTDCAgent32.exe" = "x86"
18+
19+
"V1\VSTestVideoRecorder.exe" = "x86"
20+
"VideoRecorder\VSTestVideoRecorder.exe" = "x86"
21+
}
22+
23+
$errs = @()
24+
Get-ChildItem S:\p\vstest3\artifacts\packages\Debug\Shipping -Filter *.exe -Recurse -Force | ForEach-Object {
25+
$m = & "C:\Program Files\Microsoft Visual Studio\2022\IntPreview\VC\Tools\MSVC\14.38.32919\bin\HostX86\x86\dumpbin.exe" /headers $_.FullName | Select-String "machine \((.*)\)"
26+
if (-not $m.Matches.Success) {
27+
$err = "Did not find the platform of the exe $fullName)."
28+
}
29+
30+
$platform = $m.Matches.Groups[1].Value
31+
$fullName = $_.FullName
32+
$name = $_.Name
33+
34+
if ("x86" -eq $platform) {
35+
$corFlags = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\CorFlags.exe"
36+
$corFlagsOutput = & $corFlags $fullName
37+
# this is an native x86 exe or a .net x86 that requires of prefers 32bit
38+
$platform = if ($corFlagsOutput -like "*does not have a valid managed header*" -or $corFlagsOutput -like "*32BITREQ : 1*" -or $corFlagsOutput -like "*32BITPREF : 1*") {
39+
# this is an native x86 exe or a .net x86 that requires of prefers 32bit
40+
"x86" } else {
41+
# this is a x86 executable that is built as AnyCpu and does not prefer 32-bit so it will run as x64 on 64-bit system.
42+
"x86-64" }
43+
}
44+
45+
if (($pair = $exclusions.GetEnumerator() | Where-Object { $fullName -like "*$($_.Name)" })) {
46+
if (1 -lt $($pair).Count) {
47+
$err = "Too many paths matched the query, only one match is allowed. Matches: $($pair.Name)"
48+
$errs += $err
49+
Write-Host -ForegroundColor Red Error: $err
50+
}
51+
52+
if ($platform -ne $pair.Value) {
53+
$err = "$fullName must have architecture $($pair.Value), but it was $platform."
54+
$errs += $err
55+
Write-Host -ForegroundColor Red Error: $err
56+
}
57+
}
58+
elseif ("x86" -eq $platform) {
59+
if ($name -notlike "*x86*") {
60+
$err = "$fullName has architecture $platform, and must contain x86 in the name of the executable."
61+
$errs += $err
62+
Write-Host -ForegroundColor Red Error: $err
63+
}
64+
}
65+
elseif ($platform -in "x64", "x86-64") {
66+
if ($name -like "*x86*" -or $name -like "*arm64*") {
67+
$err = "$fullName has architecture $platform, and must NOT contain x86 or arm64 in the name of the executable."
68+
$errs += $err
69+
Write-Host -ForegroundColor Red Error: $err
70+
}
71+
}
72+
elseif ("arm64" -eq $platform) {
73+
if ($name -notlike "*arm64*") {
74+
$err = "$fullName has architecture $platform, and must contain arm64 in the name of the executable."
75+
$errs += $err
76+
Write-Host -ForegroundColor Red Error: $err
77+
}
78+
}
79+
else {
80+
$err = "$fullName has unknown architecture $platform."
81+
$errs += $err
82+
Write-Host -ForegroundColor Red $err
83+
}
84+
85+
"Success: $name is $platform - $fullName"
86+
}
87+
88+
if ($errs) {
89+
throw "Fail!:`n$($errs -join "`n")"
90+
}

src/DataCollectors/DumpMinitool.arm64/DumpMinitool.arm64.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
<PropertyGroup>
55
<TargetFrameworks>net7.0;net6.0;$(NetFrameworkMinimum)</TargetFrameworks>
6-
<PlatformTarget>AnyCPU</PlatformTarget>
76
<Prefer32Bit Condition="'$(TargetFramework)' == '$(NetFrameworkMinimum)'">false</Prefer32Bit>
87
<OutputType>Exe</OutputType>
98
<IsTestProject>false</IsTestProject>
109
<RuntimeIdentifier Condition=" '$(DotNetBuildFromSource)' != 'true' ">win10-arm64</RuntimeIdentifier>
10+
<!-- Setting both RuntimeIdentifier and PlatformTarget ends up building as AnyCPU and selecting the default x86 architecture, irregardless of RuntimeIdentifier,
11+
so order here matters. -->
12+
<PlatformTarget Condition=" '$(RuntimeIdentifier)' == '' ">AnyCPU</PlatformTarget>
1113
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
1214
<ExcludeFromSourceBuild>true</ExcludeFromSourceBuild>
1315
<!--

src/testhost.x86/testhost.x86.csproj

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
<AssemblyName>testhost.x86</AssemblyName>
1313
<TargetFrameworks>net7.0;$(NetCoreAppMinimum);$(NetFrameworkMinimum);net47;net471;net472;net48</TargetFrameworks>
1414
<PlatformTarget>AnyCPU</PlatformTarget>
15+
<RuntimeIdentifier Condition="'$(DotNetBuildFromSource)' != 'true'">win7-x86</RuntimeIdentifier>
1516
<Prefer32Bit Condition=" $(TargetFramework.StartsWith('net4')) ">true</Prefer32Bit>
1617
<OutputType>Exe</OutputType>
1718
<IsTestProject>false</IsTestProject>
1819
<ApplicationManifest>app.manifest</ApplicationManifest>
20+
<!--
21+
NETSDK1201: For projects targeting .NET 8.0 and higher, specifying a RuntimeIdentifier will no longer produce a
22+
self contained app by default. To continue building self-contained apps, set the SelfContained property to true
23+
or use the -\-self-contained argument.
24+
-->
25+
<MSBuildWarningsAsMessages>NETSDK1201</MSBuildWarningsAsMessages>
26+
<NoWarn>$(NoWarn);NETSDK1201</NoWarn>
1927
</PropertyGroup>
2028
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
21-
<RuntimeIdentifier Condition="'$(DotNetBuildFromSource)' != 'true'">win7-x86</RuntimeIdentifier>
2229
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
2330
<TargetName Condition="'$(TargetFramework)' != '$(NetFrameworkMinimum)'">$(AssemblyName.Replace('.x86', '')).$(TargetFramework).x86</TargetName>
2431
</PropertyGroup>

test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Build.cs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private static void SetDotnetEnvironment()
4242
#pragma warning disable RS0030 // Do not used banned APIs
4343
Environment.SetEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0");
4444
Environment.SetEnvironmentVariable("DOTNET_ROOT", DotnetDir);
45+
Environment.SetEnvironmentVariable("DOTNET_ROOT(x86)", Path.Combine(DotnetDir, "dotnet-sdk-x86"));
4546
Environment.SetEnvironmentVariable("PATH", $"{DotnetDir};{Environment.GetEnvironmentVariable("PATH")}");
4647
#pragma warning restore RS0030 // Do not used banned APIs
4748
}

0 commit comments

Comments
 (0)