public ProjectJsonBuildIntegratedProjectSystem( string jsonConfigPath, string msbuildProjectFilePath, EnvDTEProject envDTEProject, string uniqueName) : base(jsonConfigPath, msbuildProjectFilePath) { _envDTEProject = envDTEProject; // set project id var projectId = VsHierarchyUtility.GetProjectId(envDTEProject); InternalMetadata.Add(NuGetProjectMetadataKeys.ProjectId, projectId); // Override the JSON TFM value from the csproj for UAP framework if (InternalMetadata.TryGetValue(NuGetProjectMetadataKeys.TargetFramework, out object targetFramework)) { var jsonTargetFramework = targetFramework as NuGetFramework; if (IsUAPFramework(jsonTargetFramework)) { var platfromMinVersion = VsHierarchyUtility.GetMSBuildProperty(VsHierarchyUtility.ToVsHierarchy(envDTEProject), EnvDTEProjectInfoUtility.TargetPlatformMinVersion); if (!string.IsNullOrEmpty(platfromMinVersion)) { // Found the TPMinV in csproj, store this as a new target framework to be replaced in project.json var newTargetFramework = new NuGetFramework(jsonTargetFramework.Framework, new Version(platfromMinVersion)); InternalMetadata[NuGetProjectMetadataKeys.TargetFramework] = newTargetFramework; } } } InternalMetadata.Add(NuGetProjectMetadataKeys.UniqueName, uniqueName); }
public bool TryCreateNuGetProject(EnvDTE.Project dteProject, ProjectSystemProviderContext context, out NuGetProject result) { if (dteProject == null) { throw new ArgumentNullException(nameof(dteProject)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } ThreadHelper.ThrowIfNotOnUIThread(); result = null; // The project must be an IVsHierarchy. var hierarchy = VsHierarchyUtility.ToVsHierarchy(dteProject); if (hierarchy == null) { return(false); } // Check if the project is not CPS capable or if it is CPS capable then it does not have TargetFramework(s), if so then return false if (!hierarchy.IsCapabilityMatch("CPS")) { return(false); } var buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; // read MSBuild property RestoreProjectStyle, TargetFramework, and TargetFrameworks var restoreProjectStyle = VsHierarchyUtility.GetMSBuildProperty(buildPropertyStorage, RestoreProjectStyle); var targetFramework = VsHierarchyUtility.GetMSBuildProperty(buildPropertyStorage, TargetFramework); var targetFrameworks = VsHierarchyUtility.GetMSBuildProperty(buildPropertyStorage, TargetFrameworks); // check for RestoreProjectStyle property is set and if not set to PackageReference then return false if (!(string.IsNullOrEmpty(restoreProjectStyle) || restoreProjectStyle.Equals(ProjectStyle.PackageReference.ToString(), StringComparison.OrdinalIgnoreCase))) { return(false); } // check whether TargetFramework or TargetFrameworks property is set, else return false else if (string.IsNullOrEmpty(targetFramework) && string.IsNullOrEmpty(targetFrameworks)) { return(false); } // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as IProjectServiceAccessor); var projectNames = ProjectNames.FromDTEProject(dteProject); var fullProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(dteProject); var unconfiguredProject = GetUnconfiguredProject(dteProject); result = new CpsPackageReferenceProject( dteProject.Name, EnvDTEProjectInfoUtility.GetCustomUniqueName(dteProject), fullProjectPath, _projectSystemCache, dteProject, unconfiguredProject, VsHierarchyUtility.GetProjectId(dteProject)); return(true); }