Exemplo n.º 1
0
        private async Task <string> GetTargetFrameworkStringAsync()
        {
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var projectPath        = FullName;
            var platformIdentifier = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetPlatformIdentifier);

            var platformVersion = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetPlatformVersion);

            var platformMinVersion = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetPlatformMinVersion);

            var targetFrameworkMoniker = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetFrameworkMoniker);

            // Projects supporting TargetFramework and TargetFrameworks are detected before
            // this check. The values can be passed as null here.
            var frameworkStrings = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: projectPath,
                targetFrameworks: null,
                targetFramework: null,
                targetFrameworkMoniker: targetFrameworkMoniker,
                targetPlatformIdentifier: platformIdentifier,
                targetPlatformVersion: platformVersion,
                targetPlatformMinVersion: platformMinVersion);

            return(frameworkStrings.FirstOrDefault());
        }
        /// <summary>
        /// Gets the target frameworks for the specified project.
        /// </summary>
        /// <param name="project">An <see cref="IMSBuildProject" /> representing the main project.</param>
        /// <param name="innerNodes">An <see cref="IReadOnlyDictionary{String,IMSBuildProject}" /> representing all inner projects by their target framework.</param>
        /// <returns></returns>
        internal static IReadOnlyDictionary <NuGetFramework, IMSBuildProject> GetProjectTargetFrameworks(IMSBuildProject project, IReadOnlyDictionary <string, IMSBuildProject> innerNodes)
        {
            // Get the raw list of target frameworks that the project specifies
            var projectFrameworkStrings = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: project.FullPath,
                targetFrameworks: project.GetProperty("TargetFrameworks"),
                targetFramework: project.GetProperty("TargetFramework"),
                targetFrameworkMoniker: project.GetProperty("TargetFrameworkMoniker"),
                targetPlatformIdentifier: project.GetProperty("TargetPlatformIdentifier"),
                targetPlatformVersion: project.GetProperty("TargetPlatformVersion"),
                targetPlatformMinVersion: project.GetProperty("TargetPlatformMinVersion")).ToList();

            var projectTargetFrameworks = new Dictionary <NuGetFramework, IMSBuildProject>();

            foreach (var projectTargetFramework in projectFrameworkStrings)
            {
                // Attempt to get the corresponding project instance for the target framework.  If one is not found, then the project must not target multiple frameworks
                // and the main project should be used
                if (!innerNodes.TryGetValue(projectTargetFramework, out IMSBuildProject innerNode))
                {
                    innerNode = project;
                }

                // Add the target framework and associate it with the project instance to be used for gathering details
                projectTargetFrameworks[NuGetFramework.Parse(projectTargetFramework)] = innerNode;
            }

            return(projectTargetFrameworks);
        }
        public override bool Execute()
        {
            var log = new MSBuildLogger(Log);

            log.LogDebug($"(in) ProjectPath '{ProjectPath}'");
            log.LogDebug($"(in) TargetFrameworkMoniker '{TargetFrameworkMoniker}'");
            log.LogDebug($"(in) TargetPlatformIdentifier '{TargetPlatformIdentifier}'");
            log.LogDebug($"(in) TargetPlatformVersion '{TargetPlatformVersion}'");
            log.LogDebug($"(in) TargetPlatformMinVersion '{TargetPlatformMinVersion}'");
            log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
            log.LogDebug($"(in) TargetFramework '{TargetFramework}'");

            // If no framework can be found this will return Unsupported.
            var frameworks = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: ProjectPath,
                targetFrameworks: TargetFrameworks,
                targetFramework: TargetFramework,
                targetFrameworkMoniker: TargetFrameworkMoniker,
                targetPlatformIdentifier: TargetPlatformIdentifier,
                targetPlatformVersion: TargetPlatformVersion,
                targetPlatformMinVersion: TargetPlatformMinVersion);

            ProjectTargetFrameworks = string.Join(";", frameworks);

            log.LogDebug($"(out) ProjectTargetFrameworks '{ProjectTargetFrameworks}'");

            return(true);
        }
        /// <summary>
        /// Determine the project framework string based on the project properties.
        /// </summary>
        public static string GetTargetFrameworkString(EnvDTE.Project envDTEProject)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (envDTEProject == null)
            {
                return(null);
            }

            var projectPath              = GetFullProjectPath(envDTEProject);
            var platformIdentifier       = GetPropertyValue <string>(envDTEProject, TargetPlatformIdentifier);
            var platformVersion          = GetPropertyValue <string>(envDTEProject, TargetPlatformVersion);
            var platformMinVersion       = GetPropertyValue <string>(envDTEProject, TargetPlatformMinVersion);
            var targetFrameworkMoniker   = GetPropertyValue <string>(envDTEProject, TargetFrameworkMoniker);
            var isManagementPackProject  = IsManagementPackProject(envDTEProject);
            var isXnaWindowsPhoneProject = IsXnaWindowsPhoneProject(envDTEProject);

            // Projects supporting TargetFramework and TargetFrameworks are detected before
            // this check. The values can be passed as null here.
            var frameworkStrings = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: projectPath,
                targetFrameworks: null,
                targetFramework: null,
                targetFrameworkMoniker: targetFrameworkMoniker,
                targetPlatformIdentifier: platformIdentifier,
                targetPlatformVersion: platformVersion,
                targetPlatformMinVersion: platformMinVersion,
                isManagementPackProject: isManagementPackProject,
                isXnaWindowsPhoneProject: isXnaWindowsPhoneProject);

            return(frameworkStrings.FirstOrDefault());
        }
        public static async Task <NuGetFramework> GetNuGetFrameworkAsync(
            IMSBuildProjectDataService dataService,
            string projectPath)
        {
            Assumes.Present(dataService);

            var targetPlatformIdentifier = await GetProjectPropertyAsync(dataService, TargetPlatformIdentifier);

            var targetPlatformVersion = await GetProjectPropertyAsync(dataService, TargetPlatformVersion);

            var targetPlatformMinVersion = await GetProjectPropertyAsync(dataService, TargetPlatformMinVersion);

            var targetFrameworkMoniker = await GetProjectPropertyAsync(dataService, TargetFrameworkMoniker);

            var frameworkStrings = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: projectPath,
                targetFrameworks: null,
                targetFramework: null,
                targetFrameworkMoniker: targetFrameworkMoniker,
                targetPlatformIdentifier: targetPlatformIdentifier,
                targetPlatformVersion: targetPlatformVersion,
                targetPlatformMinVersion: targetPlatformMinVersion);

            var frameworkString = frameworkStrings.FirstOrDefault();

            if (!string.IsNullOrEmpty(frameworkString))
            {
                return(NuGetFramework.Parse(frameworkString));
            }

            return(NuGetFramework.UnsupportedFramework);
        }
Exemplo n.º 6
0
        private Task <string> GetTargetFrameworkStringAsync()
        {
            var frameworkStrings = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: ProjectFilePath,
                targetFrameworks: BuildProperties.GetPropertyValue("TargetFrameworks"),
                targetFramework: BuildProperties.GetPropertyValue("TargetFramework"),
                targetFrameworkMoniker: BuildProperties.GetPropertyValue("TargetFrameworkMoniker"),
                targetPlatformIdentifier: BuildProperties.GetPropertyValue("TargetPlatformIdentifier"),
                targetPlatformVersion: BuildProperties.GetPropertyValue("TargetPlatformVersion"),
                targetPlatformMinVersion: BuildProperties.GetPropertyValue("TargetPlatformMinVersion"));

            return(Task.FromResult(frameworkStrings.FirstOrDefault()));
        }
Exemplo n.º 7
0
        public async Task <NuGetFramework> GetTargetFrameworkAsync()
        {
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var nugetFramework = NuGetFramework.UnsupportedFramework;

            var projectPath        = FullPath;
            var platformIdentifier = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetPlatformIdentifier);

            var platformVersion = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetPlatformVersion);

            var platformMinVersion = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetPlatformMinVersion);

            var targetFrameworkMoniker = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.TargetFrameworkMoniker);

            // Projects supporting TargetFramework and TargetFrameworks are detected before
            // this check. The values can be passed as null here.
            var frameworkStrings = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                projectFilePath: projectPath,
                targetFrameworks: null,
                targetFramework: null,
                targetFrameworkMoniker: targetFrameworkMoniker,
                targetPlatformIdentifier: platformIdentifier,
                targetPlatformVersion: platformVersion,
                targetPlatformMinVersion: platformMinVersion);

            var frameworkString = frameworkStrings.FirstOrDefault();

            if (!string.IsNullOrEmpty(frameworkString))
            {
                nugetFramework = NuGetFramework.Parse(frameworkString);
            }

            return(nugetFramework);
        }
 /// <summary>
 /// Test helper
 /// </summary>
 private static List <NuGetFramework> GetFrameworks(
     string projectFilePath,
     string targetFrameworks         = "",
     string targetFramework          = "",
     string targetFrameworkMoniker   = "",
     string targetPlatformIdentifier = "",
     string targetPlatformVersion    = "",
     string targetPlatformMinVersion = "",
     bool isXnaWindowsPhoneProject   = false,
     bool isManagementPackProject    = false)
 {
     return(MSBuildProjectFrameworkUtility.GetProjectFrameworks(
                MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
                    projectFilePath,
                    targetFrameworks,
                    targetFramework,
                    targetFrameworkMoniker,
                    targetPlatformIdentifier,
                    targetPlatformVersion,
                    targetPlatformMinVersion,
                    isXnaWindowsPhoneProject,
                    isManagementPackProject))
            .ToList());
 }