Skip to content

Commit deceebc

Browse files
itminusjkotalik
authored andcommitted
Fix ANCM search for dotnet.exe (#18311)
1 parent 116799f commit deceebc

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ HostFxrResolver::GetHostFxrParameters(
145145
}
146146

147147
BOOL
148-
HostFxrResolver::IsDotnetExecutable(const std::filesystem::path & dotnetPath)
148+
HostFxrResolver::IsDotnetExecutable(const std::filesystem::path& dotnetPath)
149149
{
150-
return ends_with(dotnetPath, L"dotnet.exe", true);
150+
std::wstring filename = dotnetPath.filename().wstring();
151+
return equals_ignore_case(filename, L"dotnet.exe");
151152
}
152153

153154
void

src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</ItemGroup>
4444
<ItemGroup>
4545
<ClCompile Include="ConfigUtilityTests.cpp" />
46+
<ClCompile Include="dotnet_exe_path_tests.cpp" />
4647
<ClCompile Include="GlobalVersionTests.cpp" />
4748
<ClCompile Include="Helpers.cpp" />
4849
<ClCompile Include="inprocess_application_tests.cpp" />
@@ -71,6 +72,17 @@
7172
<Project>{d57ea297-6dc2-4bc0-8c91-334863327863}</Project>
7273
</ProjectReference>
7374
</ItemGroup>
75+
<ItemGroup>
76+
<Content Include="Fake\hello-dotnet.exe">
77+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
78+
</Content>
79+
<Content Include="Fake\hello-dotnet.dll">
80+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
81+
</Content>
82+
<Content Include="Fake\hostfxr.dll">
83+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
84+
</Content>
85+
</ItemGroup>
7486
<ItemDefinitionGroup />
7587
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
7688
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -185,4 +197,4 @@
185197
</AdditionalDependencies>
186198
</Lib>
187199
</ItemDefinitionGroup>
188-
</Project>
200+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this a is faked hello-dotnet.dll used for tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this a is faked hello-dotnet.exe used for tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this a is faked hostfxr.dll used for tests
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
#include "stdafx.h"
5+
6+
#include <array>
7+
#include "fakeclasses.h"
8+
#include "HostFxrResolver.h"
9+
10+
using ::testing::_;
11+
using ::testing::NiceMock;
12+
13+
// Externals defined in inprocess
14+
namespace InprocessTests
15+
{
16+
17+
TEST(Dotnet_EXE_Path_Tests, EndWith_dotnet)
18+
{
19+
HostFxrResolver resolver;
20+
std::filesystem::path hostFxrDllPath;
21+
std::vector<std::wstring> arguments;
22+
ErrorContext errorContext;
23+
auto currentPath = std::filesystem::current_path();
24+
auto appPath= currentPath /= L"Fake";
25+
auto processPath = L"hello-dotnet";
26+
auto args = L"-a --tag t -x";
27+
std::filesystem::path knownDotnetLocation=L"C:/Program Files/dotnet";
28+
// expected no exception should be thrown
29+
HostFxrResolver::GetHostFxrParameters(
30+
processPath,
31+
appPath,
32+
args,
33+
hostFxrDllPath,
34+
knownDotnetLocation,
35+
arguments,
36+
errorContext);
37+
38+
ASSERT_TRUE(ends_with(arguments[0], L"\\Fake\\hello-dotnet.exe", true));
39+
ASSERT_STREQ(arguments[1].c_str(), L"-a");
40+
ASSERT_STREQ(arguments[2].c_str(), L"--tag");
41+
ASSERT_STREQ(arguments[3].c_str(), L"t");
42+
ASSERT_STREQ(arguments[4].c_str(), L"-x");
43+
}
44+
}

0 commit comments

Comments
 (0)