private void EnsureProperties() { if (_initialized) { return; } _projectName = _projectNameProperty.GetValue <string>(_projectInstance); var projectType = _projectTypeProperty.GetValue <SolutionProjectType>(_projectInstance); var relativePath = _relativePathProperty.GetValue <string>(_projectInstance); _isWebSite = projectType == SolutionProjectType.WebProject; // When using websites with IISExpress, the relative path property becomes a URL. // When that happens we're going to grab the path from the Release.AspNetCompiler.PhysicalPath // property in the solution. Uri uri; if (_isWebSite && Uri.TryCreate(relativePath, UriKind.Absolute, out uri)) { var aspNetConfigurations = _aspNetConfigurationsProperty.GetValue <Hashtable>(_projectInstance); // Use the release configuration and debug if it isn't available object configurationObject = aspNetConfigurations["Release"] ?? aspNetConfigurations["Debug"]; // REVIEW: Is there always a configuration object (i.e. can this ever be null?) // The aspNetPhysicalPath contains the relative to the website FieldInfo aspNetPhysicalPathField = configurationObject.GetType().GetField("aspNetPhysicalPath", BindingFlags.NonPublic | BindingFlags.Instance); relativePath = (string)aspNetPhysicalPathField.GetValue(configurationObject); } _absolutePath = Path.Combine(Path.GetDirectoryName(_solutionPath), relativePath); if (FileSystemHelpers.FileExists(_absolutePath) && DeploymentHelper.IsMsBuildProject(_absolutePath)) { // used to determine project type from project file _projectTypeGuids = VsHelper.GetProjectTypeGuids(_absolutePath); _isAspNetCore = AspNetCoreHelper.IsDotnetCoreFromProjectFile(_absolutePath, _projectTypeGuids); _isWap = VsHelper.IsWap(_projectTypeGuids); _isExecutable = VsHelper.IsExecutableProject(_absolutePath); _isFunctionApp = FunctionAppHelper.LooksLikeFunctionApp(); _isDotNetCore3 = VsHelper.IsDotNetCore3(_absolutePath); } else { _projectTypeGuids = Enumerable.Empty <Guid>(); } _initialized = true; }
public static bool IsDotnetCoreFromProjectFile(string projectPath, IEnumerable <Guid> projectTypeGuids) { if (projectPath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)) { // for csproj, need to 1st make sure its dotnet core ==> !projectTypeGuids.Any() // Common Project System-style no longer has projectTypeGuid if (projectTypeGuids.Any()) { return(false); } // ASP.NET CORE 2.2 and lower requires these // either <PackageReference Include="Microsoft.AspNetCore" Version="..." /> // for dotnet core project created with 2.0 toolings look for "Microsoft.AspNetCore.All" // for dotnet core project created with 2.1 toolings look for "Microsoft.AspNetCore.App" if (VsHelper.IncludesAnyReferencePackage(projectPath, "Microsoft.AspNetCore", "Microsoft.AspNetCore.All", "Microsoft.AspNetCore.App")) { return(true); } // look for web.config or wwwroot if (IsWebAppFromFolderStruct(projectPath)) { return(true); } // if ASP.NET CORE 3.X check for <Project Sdk="Microsoft.NET.Sdk.Web"> return(VsHelper.IsAspNetCoreSDK(VsHelper.GetProjectSDK(projectPath)) && VsHelper.IsDotNetCore3(VsHelper.GetTargetFramework(projectPath))); } else if (projectPath.EndsWith(".xproj", StringComparison.OrdinalIgnoreCase)) { // for dotnet core preview 2 and before return(IsWebAppFromFolderStruct(projectPath)); } return(false); }