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 configuraiton 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)) { // used to determine project type _projectTypeGuids = VsHelper.GetProjectTypeGuids(_absolutePath); if (AspNetCoreHelper.IsDotnetCoreFromProjectFile(_absolutePath, _projectTypeGuids)) { _isAspNetCore = true; } else if (projectType == SolutionProjectType.KnownToBeMSBuildFormat) { // KnownToBeMSBuildFormat: C#, VB, and VJ# projects // Check if it's a wap _isWap = VsHelper.IsWap(_projectTypeGuids); _isExecutable = VsHelper.IsExecutableProject(_absolutePath); } else if (FunctionAppHelper.LooksLikeFunctionApp()) { _isFunctionApp = true; } } else { _projectTypeGuids = Enumerable.Empty <Guid>(); } _initialized = true; }
private void EnsureProperties() { if (_initialized) { return; } _projectName = _projectNameProperty.GetValue <string>(_projectInstance); var projectType = _projectTypeProperty.GetValue <SolutionProjectType>(_projectInstance); var projectExtension = _projectExtensionProperty.GetValue <string>(_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 configuraiton 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 (projectType == SolutionProjectType.KnownToBeMSBuildFormat && File.Exists(_absolutePath)) { // If the project is an msbuild project then extra the project type guids _projectTypeGuids = VsHelper.GetProjectTypeGuids(_absolutePath); // Check if it's a wap _isWap = VsHelper.IsWap(_projectTypeGuids); _isExecutable = VsHelper.IsExecutableProject(_absolutePath); } else if (projectExtension.Equals(".xproj", StringComparison.OrdinalIgnoreCase) && File.Exists(_absolutePath)) { var projectPath = Path.Combine(Path.GetDirectoryName(_absolutePath), "project.json"); if (AspNetCoreHelper.IsWebApplicationProjectJsonFile(projectPath)) { _isAspNetCore = true; _absolutePath = projectPath; } _projectTypeGuids = Enumerable.Empty <Guid>(); } else { _projectTypeGuids = Enumerable.Empty <Guid>(); } _initialized = true; }