diff --git a/IISIntegration.sln b/IISIntegration.sln index adaa839434..e861a3045f 100644 --- a/IISIntegration.sln +++ b/IISIntegration.sln @@ -1,6 +1,7 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27130.2010 +VisualStudioVersion = 15.0.27130.2020 MinimumVisualStudioVersion = 15.0.26730.03 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{04B1EDB6-E967-4D25-89B9-E6F8304038CD}" ProjectSection(SolutionItems) = preProject @@ -53,7 +54,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CommonLib", "src\CommonLib\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RequestHandler", "src\RequestHandler\RequestHandler.vcxproj", "{D57EA297-6DC2-4BC0-8C91-334863327863}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Server.IIS", "src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj", "{46A8612B-418B-4D70-B3A7-A21DD0627473}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.IIS", "src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj", "{46A8612B-418B-4D70-B3A7-A21DD0627473}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -202,16 +203,16 @@ Global {D57EA297-6DC2-4BC0-8C91-334863327863}.Release|x86.Build.0 = Release|Win32 {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|Any CPU.Build.0 = Debug|Any CPU - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.ActiveCfg = Debug|x64 - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.Build.0 = Debug|x64 - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.ActiveCfg = Debug|x86 - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.Build.0 = Debug|x86 + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.ActiveCfg = Debug|Any CPU + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.Build.0 = Debug|Any CPU + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.ActiveCfg = Debug|Any CPU + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.Build.0 = Debug|Any CPU {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|Any CPU.ActiveCfg = Release|Any CPU {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|Any CPU.Build.0 = Release|Any CPU - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.ActiveCfg = Release|x64 - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.Build.0 = Release|x64 - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.ActiveCfg = Release|x86 - {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.Build.0 = Release|x86 + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.ActiveCfg = Release|Any CPU + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.Build.0 = Release|Any CPU + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.ActiveCfg = Release|Any CPU + {46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/CommonLib/hostfxr_utility.cpp b/src/CommonLib/hostfxr_utility.cpp index ce4d7fc9ba..2b93ac07d7 100644 --- a/src/CommonLib/hostfxr_utility.cpp +++ b/src/CommonLib/hostfxr_utility.cpp @@ -25,24 +25,21 @@ HOSTFXR_UTILITY::~HOSTFXR_UTILITY() // HRESULT HOSTFXR_UTILITY::GetStandaloneHostfxrParameters( + PCWSTR pwzExePath, ASPNETCORE_CONFIG *pConfig ) { HRESULT hr = S_OK; - STRU struExePath; STRU struDllPath; STRU struArguments; DWORD dwPosition; - hr = UTILITY::ConvertPathToFullPath(pConfig->QueryProcessPath()->QueryStr(), - pConfig->QueryApplicationPhysicalPath()->QueryStr(), - &struExePath); if (FAILED(hr)) { goto Finished; } - if (FAILED(hr = struDllPath.Copy(struExePath))) + if (FAILED(hr = struDllPath.Copy(pwzExePath))) { goto Finished; } @@ -61,7 +58,7 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters( { goto Finished; } - + if (!UTILITY::CheckIfFileExists(struDllPath.QueryStr())) { // Treat access issue as File not found @@ -76,7 +73,7 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters( goto Finished; } - if (FAILED(hr = SetHostFxrArguments(&struArguments, &struExePath, pConfig))) + if (FAILED(hr = SetHostFxrArguments(struArguments.QueryStr(), pwzExePath, pConfig))) { goto Finished; } @@ -94,18 +91,32 @@ HOSTFXR_UTILITY::GetHostFxrParameters( HRESULT hr = S_OK; STRU struSystemPathVariable; STRU struHostFxrPath; - STRU strDotnetExeLocation; - STRU strHostFxrSearchExpression; - STRU strHighestDotnetVersion; + STRU struExeLocation; + STRU struHostFxrSearchExpression; + STRU struHighestDotnetVersion; std::vector vVersionFolders; DWORD dwPosition; DWORD dwPathLength = MAX_PATH; DWORD dwDotnetLength = 0; BOOL fFound = FALSE; - if (UTILITY::CheckIfFileExists(pConfig->QueryProcessPath()->QueryStr())) + // Convert the process path an absolute path. + hr = UTILITY::ConvertPathToFullPath( + pConfig->QueryProcessPath()->QueryStr(), + pConfig->QueryApplicationPhysicalPath()->QueryStr(), + &struExeLocation + ); + + if (FAILED(hr)) { - hr = UTILITY::ConvertPathToFullPath(L"hostfxr.dll", pConfig->QueryApplicationPath()->QueryStr(), &struHostFxrPath); + goto Finished; + } + + if (UTILITY::CheckIfFileExists(struExeLocation.QueryStr())) + { + // Check if hostfxr is in this folder, if it is, we are a standalone application, + // else we assume we received an absolute path to dotnet.exe + hr = UTILITY::ConvertPathToFullPath(L".\\hostfxr.dll", pConfig->QueryApplicationPhysicalPath()->QueryStr(), &struHostFxrPath); if (FAILED(hr)) { goto Finished; @@ -119,54 +130,44 @@ HOSTFXR_UTILITY::GetHostFxrParameters( goto Finished; } - hr = GetStandaloneHostfxrParameters(pConfig); + hr = GetStandaloneHostfxrParameters(struExeLocation.QueryStr(), pConfig); goto Finished; } - else + } + else + { + if (FAILED(hr = struExeLocation.Resize(MAX_PATH))) { - hr = UTILITY::ConvertPathToFullPath( - pConfig->QueryProcessPath()->QueryStr(), - pConfig->QueryApplicationPath()->QueryStr(), - &strDotnetExeLocation - ); - if (FAILED(hr)) + goto Finished; + } + + while (!fFound) + { + dwDotnetLength = SearchPath(NULL, L"dotnet", L".exe", dwPathLength, struExeLocation.QueryStr(), NULL); + if (dwDotnetLength == 0) { + hr = GetLastError(); + // Could not find dotnet goto Finished; } + else if (dwDotnetLength == dwPathLength) + { + // Increase size + dwPathLength *= 2; + if (FAILED(hr = struExeLocation.Resize(dwPathLength))) + { + goto Finished; + } + } + else + { + fFound = TRUE; + } } } - if (FAILED(hr = strDotnetExeLocation.Resize(MAX_PATH))) - { - goto Finished; - } - - while (!fFound) - { - dwDotnetLength = SearchPath(NULL, L"dotnet", L".exe", dwPathLength, strDotnetExeLocation.QueryStr(), NULL); - if (dwDotnetLength == 0) - { - hr = GetLastError(); - // Could not find dotnet - goto Finished; - } - else if (dwDotnetLength == dwPathLength) - { - // Increase size - dwPathLength *= 2; - if (FAILED(hr = strDotnetExeLocation.Resize(dwPathLength))) - { - goto Finished; - } - } - else - { - fFound = TRUE; - } - } - - if (FAILED(hr = strDotnetExeLocation.SyncWithBuffer()) - || FAILED(hr = struHostFxrPath.Copy(strDotnetExeLocation))) + if (FAILED(hr = struExeLocation.SyncWithBuffer()) + || FAILED(hr = struHostFxrPath.Copy(struExeLocation))) { goto Finished; } @@ -200,13 +201,13 @@ HOSTFXR_UTILITY::GetHostFxrParameters( } // Find all folders under host\\fxr\\ for version numbers. - hr = strHostFxrSearchExpression.Copy(struHostFxrPath); + hr = struHostFxrSearchExpression.Copy(struHostFxrPath); if (FAILED(hr)) { goto Finished; } - hr = strHostFxrSearchExpression.Append(L"\\*"); + hr = struHostFxrSearchExpression.Append(L"\\*"); if (FAILED(hr)) { goto Finished; @@ -214,7 +215,7 @@ HOSTFXR_UTILITY::GetHostFxrParameters( // As we use the logic from core-setup, we are opting to use std here. // TODO remove all uses of std? - UTILITY::FindDotNetFolders(strHostFxrSearchExpression.QueryStr(), &vVersionFolders); + UTILITY::FindDotNetFolders(struHostFxrSearchExpression.QueryStr(), &vVersionFolders); if (vVersionFolders.size() == 0) { @@ -223,14 +224,14 @@ HOSTFXR_UTILITY::GetHostFxrParameters( goto Finished; } - hr = UTILITY::FindHighestDotNetVersion(vVersionFolders, &strHighestDotnetVersion); + hr = UTILITY::FindHighestDotNetVersion(vVersionFolders, &struHighestDotnetVersion); if (FAILED(hr)) { goto Finished; } if (FAILED(hr = struHostFxrPath.Append(L"\\")) - || FAILED(hr = struHostFxrPath.Append(strHighestDotnetVersion.QueryStr())) + || FAILED(hr = struHostFxrPath.Append(struHighestDotnetVersion.QueryStr())) || FAILED(hr = struHostFxrPath.Append(L"\\hostfxr.dll"))) { goto Finished; @@ -241,8 +242,8 @@ HOSTFXR_UTILITY::GetHostFxrParameters( hr = ERROR_FILE_INVALID; goto Finished; } - - if (FAILED(hr = SetHostFxrArguments(pConfig->QueryArguments(), &strDotnetExeLocation, pConfig))) + + if (FAILED(hr = SetHostFxrArguments(pConfig->QueryArguments()->QueryStr(), struExeLocation.QueryStr(), pConfig))) { goto Finished; } @@ -263,12 +264,12 @@ Finished: // Arg structure: // argv[0] = Path to exe activating hostfxr. // argv[1] = L"exec" -// argv[2] = first argument specified in the arguments portion of aspnetcore config. +// argv[2] = absolute path to dll. // HRESULT HOSTFXR_UTILITY::SetHostFxrArguments( - STRU* struArgumentsFromConfig, - STRU* pstruExePath, + PCWSTR pwzArgumentsFromConfig, + PCWSTR pwzExePath, ASPNETCORE_CONFIG* pConfig ) { @@ -276,30 +277,89 @@ HOSTFXR_UTILITY::SetHostFxrArguments( INT argc = 0; PCWSTR* argv = NULL; LPWSTR* pwzArgs = NULL; + STRU struTempPath; + DWORD dwArgsProcessed = 0; - pwzArgs = CommandLineToArgvW(struArgumentsFromConfig->QueryStr(), &argc); + pwzArgs = CommandLineToArgvW(pwzArgumentsFromConfig, &argc); if (pwzArgs == NULL) { - goto Finished; + hr = HRESULT_FROM_WIN32(GetLastError()); + goto Failure; + } + + if (argc < 1) + { + // Invalid arguments + hr = E_INVALIDARG; + goto Failure; } argv = new PCWSTR[argc + 2]; if (argv == NULL) { hr = E_OUTOFMEMORY; - goto Finished; + goto Failure; } - argv[0] = SysAllocString(pstruExePath->QueryStr()); - argv[1] = SysAllocString(L"exec"); + argv[0] = SysAllocString(pwzExePath); - for (INT i = 0; i < argc; i++) + if (argv[0] == NULL) + { + hr = E_OUTOFMEMORY; + goto Failure; + } + dwArgsProcessed++; + + argv[1] = SysAllocString(L"exec"); + if (argv[1] == NULL) + { + hr = E_OUTOFMEMORY; + goto Failure; + } + dwArgsProcessed++; + + // Try to convert the application dll from a relative to an absolute path + // Don't record this failure as pwzArgs[0] may already be an absolute path to the dll. + if (SUCCEEDED(UTILITY::ConvertPathToFullPath(pwzArgs[0], pConfig->QueryApplicationPhysicalPath()->QueryStr(), &struTempPath))) + { + argv[2] = SysAllocString(struTempPath.QueryStr()); + } + else + { + argv[2] = SysAllocString(pwzArgs[0]); + } + if (argv[2] == NULL) + { + hr = E_OUTOFMEMORY; + goto Failure; + } + dwArgsProcessed++; + + for (INT i = 1; i < argc; i++) { argv[i + 2] = SysAllocString(pwzArgs[i]); + if (argv[i + 2] == NULL) + { + hr = E_OUTOFMEMORY; + goto Failure; + } + dwArgsProcessed++; } pConfig->SetHostFxrArguments(argc + 2, argv); + goto Finished; + +Failure: + if (argv != NULL) + { + for (DWORD i = 0; i < dwArgsProcessed; i++) + { + SysFreeString((BSTR)argv[i]); + } + } + + delete[] argv; Finished: if (pwzArgs != NULL) @@ -308,4 +368,4 @@ Finished: DBG_ASSERT(pwzArgs == NULL); } return hr; -} \ No newline at end of file +} diff --git a/src/CommonLib/hostfxr_utility.h b/src/CommonLib/hostfxr_utility.h index ca3d9f8e77..ffa552bcb7 100644 --- a/src/CommonLib/hostfxr_utility.h +++ b/src/CommonLib/hostfxr_utility.h @@ -23,15 +23,16 @@ private: static HRESULT GetStandaloneHostfxrParameters( + PCWSTR pStruExePath, ASPNETCORE_CONFIG *pConfig ); static HRESULT SetHostFxrArguments( - STRU * struArguments, - STRU * pstruExePath, - ASPNETCORE_CONFIG *pConfig + PCWSTR struArguments, + PCWSTR pStruExePath, + ASPNETCORE_CONFIG *pConfig ); }; diff --git a/src/CommonLib/stdafx.h b/src/CommonLib/stdafx.h index 2d4fc7ee47..c3e3a35a26 100644 --- a/src/CommonLib/stdafx.h +++ b/src/CommonLib/stdafx.h @@ -13,6 +13,7 @@ #include #include #include +#include "Shlwapi.h" #include "..\IISLib\hashtable.h" #include "..\IISLib\stringu.h" #include "..\IISLib\stringa.h" diff --git a/src/CommonLib/utility.cxx b/src/CommonLib/utility.cxx index b4dd25a9e5..47087a4023 100644 --- a/src/CommonLib/utility.cxx +++ b/src/CommonLib/utility.cxx @@ -384,7 +384,7 @@ UTILITY::ConvertPathToFullPath( LPWSTR pszFullPath = NULL; // if relative path, prefix with root path and then convert to absolute path. - if ( pszPath[0] == L'.' ) + if ( PathIsRelative(pszPath) ) { hr = strFileFullPath.Copy(pszRootPath); if(FAILED(hr)) diff --git a/test/IISIntegration.IISServerFunctionalTests/AuthenticationTests.cs b/test/IISIntegration.IISServerFunctionalTests/AuthenticationTests.cs index a8b74365ac..2a7eaedbee 100644 --- a/test/IISIntegration.IISServerFunctionalTests/AuthenticationTests.cs +++ b/test/IISIntegration.IISServerFunctionalTests/AuthenticationTests.cs @@ -48,7 +48,13 @@ namespace IISIntegration.IISServerFunctionalTests ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null, SiteName = "HttpTestSite", // This is configured in the Http.config TargetFramework = "netcoreapp2.0", - ApplicationType = ApplicationType.Portable + ApplicationType = ApplicationType.Portable, + Configuration = +#if DEBUG + "Debug" +#else + "Release" +#endif }; using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) diff --git a/test/IISIntegration.IISServerFunctionalTests/FeatureCollectionTests.cs b/test/IISIntegration.IISServerFunctionalTests/FeatureCollectionTests.cs index 68a9f3cf72..8c5c0ab69b 100644 --- a/test/IISIntegration.IISServerFunctionalTests/FeatureCollectionTests.cs +++ b/test/IISIntegration.IISServerFunctionalTests/FeatureCollectionTests.cs @@ -47,6 +47,12 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests SiteName = "HttpTestSite", // This is configured in the Http.config TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0", ApplicationType = applicationType, + Configuration = +#if DEBUG + "Debug" +#else + "Release" +#endif }; using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) diff --git a/test/IISIntegration.IISServerFunctionalTests/HelloWorldTests.cs b/test/IISIntegration.IISServerFunctionalTests/HelloWorldTests.cs index 610ac8c977..088874867e 100644 --- a/test/IISIntegration.IISServerFunctionalTests/HelloWorldTests.cs +++ b/test/IISIntegration.IISServerFunctionalTests/HelloWorldTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests { } - [Fact(Skip = "See https://github.com/aspnet/IISIntegration/issues/424")] + [Fact(Skip = "See https://github.com/aspnet/IISIntegration/issues/515")] public Task HelloWorld_InProcess_IISExpress_CoreClr_X64_Portable() { return HelloWorld(RuntimeFlavor.CoreClr, ApplicationType.Portable); @@ -42,7 +42,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null, SiteName = "HttpTestSite", // This is configured in the Http.config TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0", - ApplicationType = applicationType + ApplicationType = applicationType, + Configuration = +#if DEBUG + "Debug" +#else + "Release" +#endif }; using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) diff --git a/test/IISIntegration.IISServerFunctionalTests/Http.config b/test/IISIntegration.IISServerFunctionalTests/Http.config index c044b3294c..3ab0c4c1b0 100644 --- a/test/IISIntegration.IISServerFunctionalTests/Http.config +++ b/test/IISIntegration.IISServerFunctionalTests/Http.config @@ -253,7 +253,7 @@ - + diff --git a/test/IISIntegration.IISServerFunctionalTests/LargeResponseBodyTests.cs b/test/IISIntegration.IISServerFunctionalTests/LargeResponseBodyTests.cs index 9dd82e93a3..5db5e5ac1a 100644 --- a/test/IISIntegration.IISServerFunctionalTests/LargeResponseBodyTests.cs +++ b/test/IISIntegration.IISServerFunctionalTests/LargeResponseBodyTests.cs @@ -48,7 +48,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null, SiteName = "HttpTestSite", // This is configured in the Http.config TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0", - ApplicationType = applicationType + ApplicationType = applicationType, + Configuration = +#if DEBUG + "Debug" +#else + "Release" +#endif }; using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) diff --git a/test/IISIntegration.IISServerFunctionalTests/ResponseHeaderTests.cs b/test/IISIntegration.IISServerFunctionalTests/ResponseHeaderTests.cs index 19a73c8004..51fb1a5276 100644 --- a/test/IISIntegration.IISServerFunctionalTests/ResponseHeaderTests.cs +++ b/test/IISIntegration.IISServerFunctionalTests/ResponseHeaderTests.cs @@ -46,7 +46,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null, SiteName = "HttpTestSite", // This is configured in the Http.config TargetFramework = "netcoreapp2.0", - ApplicationType = applicationType + ApplicationType = applicationType, + Configuration = +#if DEBUG + "Debug" +#else + "Release" +#endif }; using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) diff --git a/test/IISIntegration.IISServerFunctionalTests/ResponseInvalidOrderingTests.cs b/test/IISIntegration.IISServerFunctionalTests/ResponseInvalidOrderingTests.cs index 90a540ee2e..3a387cc2a8 100644 --- a/test/IISIntegration.IISServerFunctionalTests/ResponseInvalidOrderingTests.cs +++ b/test/IISIntegration.IISServerFunctionalTests/ResponseInvalidOrderingTests.cs @@ -42,7 +42,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null, SiteName = "HttpTestSite", // This is configured in the Http.config TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0", - ApplicationType = applicationType + ApplicationType = applicationType, + Configuration = +#if DEBUG + "Debug" +#else + "Release" +#endif }; using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) diff --git a/test/IISTestSite/IISTestSite.csproj b/test/IISTestSite/IISTestSite.csproj index ada6f99c59..aa9239d51e 100644 --- a/test/IISTestSite/IISTestSite.csproj +++ b/test/IISTestSite/IISTestSite.csproj @@ -16,7 +16,7 @@ - +