예제 #1
0
        private void EnsureProperties()
        {
            if (_initialized)
            {
                return;
            }

            _projectName = _projectNameProperty.GetValue <string>(_projectInstance);
            var relativePath = _relativePathProperty.GetValue <string>(_projectInstance);
            var projectType  = _projectTypeProperty.GetValue <SolutionProjectType>(_projectInstance);

            _absolutePath = Path.Combine(Path.GetDirectoryName(_solutionPath), relativePath);
            _isWebSite    = projectType == SolutionProjectType.WebProject;

            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);
            }
            else
            {
                _projectTypeGuids = Enumerable.Empty <Guid>();
            }

            _initialized = true;
        }
예제 #2
0
        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

                // 2ndly, look for sign of web project
                // 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"
                // for preview3 its web.config file
                return(!projectTypeGuids.Any() &&
                       (VsHelper.IncludesAnyReferencePackage(projectPath,
                                                             "Microsoft.AspNetCore",
                                                             "Microsoft.AspNetCore.All",
                                                             "Microsoft.AspNetCore.App") ||
                        IsWebAppFromFolderStruct(projectPath)));
            }
            else if (projectPath.EndsWith(".xproj", StringComparison.OrdinalIgnoreCase))
            {
                // for dotnet core preview 2 and before
                return(IsWebAppFromFolderStruct(projectPath));
            }
            return(false);
        }
예제 #3
0
        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(".kproj", StringComparison.OrdinalIgnoreCase) && File.Exists(_absolutePath))
            {
                _isProjectK       = true;
                _absolutePath     = Path.Combine(Path.GetDirectoryName(_absolutePath), "project.json");
                _projectTypeGuids = Enumerable.Empty <Guid>();
            }
            else
            {
                _projectTypeGuids = Enumerable.Empty <Guid>();
            }

            _initialized = true;
        }
예제 #4
0
        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();
                _targetFramework = VsHelper.GetTargetFramework(_absolutePath);
            }
            else
            {
                _projectTypeGuids = Enumerable.Empty <Guid>();
            }

            _initialized = true;
        }
예제 #5
0
        public static void ThrowsIfVersionMismatch(string projectPath)
        {
            // "<AzureFunctionsVersion>v2</AzureFunctionsVersion>" exists in v2 csproj
            var properties          = VsHelper.GetPropertyValues(projectPath, "AzureFunctionsVersion", VsHelper.Csproj.newFormat);
            var projectMajorVersion = String.Equals(properties.FirstOrDefault(), "v2", StringComparison.OrdinalIgnoreCase) ? FuncVersion.V2 : FuncVersion.V1;
            var runtimeMajorVersion = GetFunctionRuntimeMajorVersion();

            if (runtimeMajorVersion == projectMajorVersion)
            {
                // check succeeded
                return;
            }

            throw new InvalidOperationException($@"Your function app is targeting {projectMajorVersion}, but Azure host has function version {runtimeMajorVersion}, 
please change the version using the portal or update your 'FUNCTIONS_EXTENSION_VERSION' appsetting and retry");
        }
예제 #6
0
 public static bool IsDotnetCoreFromProjectFile(string projectPath, IEnumerable <Guid> projectTypeGuids)
 {
     if (projectPath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
     {
         // for dotnet core preview 3 and after
         // if its .csproj, look for <PackageReference Include="Microsoft.AspNetCore" Version="..." />
         return(!projectTypeGuids.Any() &&
                (VsHelper.IncludesReferencePackage(projectPath, "Microsoft.AspNetCore") ||
                 IsWebAppFromFolderStruct(projectPath)));
     }
     else if (projectPath.EndsWith(".xproj", StringComparison.OrdinalIgnoreCase))
     {
         // for dotnet core preview 2 and before
         return(IsWebAppFromFolderStruct(projectPath));
     }
     return(false);
 }
예제 #7
0
        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);
        }
예제 #8
0
 public static bool IsCSharpFunctionFromProjectFile(string projectPath)
 {
     return(VsHelper.IncludesAnyReferencePackage(projectPath, "Microsoft.NET.Sdk.Functions"));
 }
예제 #9
0
 public static void ThrowsIfVersionMismatch(string projectPath)
 {
     // "<AzureFunctionsVersion>v2</AzureFunctionsVersion>" exists in v2 csproj
     ThrowsIfVersionMismatch(VsHelper.GetPropertyValues(projectPath, "AzureFunctionsVersion", VsHelper.Csproj.newFormat));
 }