public App() { InitializeComponent(); /* Use default styles */ ProjectStyle.Init(this); /* Use XAML styles in App.xaml file */ //ProjectStyle.Init(this, "Style.Configuration"); /* Use Custom styles configuration */ //var customConfiguration = new StyleConfiguration //{ // ColorConfiguration = new ColorConfiguration // { // // Set properties // }, // FontConfiguration = new FontConfiguration // { // // Set properties // } //}; //ProjectStyle.Init(this, customConfiguration); MainPage = new MainPage(); }
public BaselineProject(UnconfiguredProject project, ImmutableArray <string> globalProperties, ProjectStyle projectStyle, ProjectOutputType outputType) : this() { GlobalProperties = globalProperties; Project = project ?? throw new ArgumentNullException(nameof(project)); ProjectStyle = projectStyle; OutputType = outputType; }
public BaselineProject(UnconfiguredProject project, ImmutableArray <string> globalProperties, ImmutableDictionary <string, string> targetProjectProperties, ProjectStyle projectStyle) : this() { GlobalProperties = globalProperties; TargetProjectProperties = targetProjectProperties; Project = project ?? throw new ArgumentNullException(nameof(project)); ProjectStyle = projectStyle; }
private static string AdjustTargetTFM(ProjectStyle projectStyle, ProjectOutputType outputType, string candidateTargetTFM) { if (candidateTargetTFM.ContainsIgnoreCase(MSBuildFacts.Net5) && projectStyle is ProjectStyle.WindowsDesktop) { return(MSBuildFacts.Net5Windows); } if (projectStyle is not ProjectStyle.MSTest && projectStyle is not ProjectStyle.Web && outputType is ProjectOutputType.Library) { return(MSBuildFacts.NetStandard20); } //conditional checks for Xamarin Project Styles if (projectStyle is ProjectStyle.XamarinDroid) { return(XamarinFacts.Net6XamarinAndroid); } if (projectStyle is ProjectStyle.XamariniOS) { return(XamarinFacts.Net6XamariniOS); } return(candidateTargetTFM); }
public RestoreResult( bool success, IEnumerable <RestoreTargetGraph> restoreGraphs, IEnumerable <CompatibilityCheckResult> compatibilityCheckResults, IEnumerable <MSBuildOutputFile> msbuildFiles, LockFile lockFile, LockFile previousLockFile, string lockFilePath, CacheFile cacheFile, string cacheFilePath, string packagesLockFilePath, PackagesLockFile packagesLockFile, string dependencyGraphSpecFilePath, DependencyGraphSpec dependencyGraphSpec, ProjectStyle projectStyle, TimeSpan elapsedTime) { Success = success; RestoreGraphs = restoreGraphs; CompatibilityCheckResults = compatibilityCheckResults; MSBuildOutputFiles = msbuildFiles; LockFile = lockFile; LockFilePath = lockFilePath; PreviousLockFile = previousLockFile; CacheFile = cacheFile; CacheFilePath = cacheFilePath; _newPackagesLockFilePath = packagesLockFilePath; _newPackagesLockFile = packagesLockFile; _dependencyGraphSpecFilePath = dependencyGraphSpecFilePath; _dependencyGraphSpec = dependencyGraphSpec; ProjectStyle = projectStyle; ElapsedTime = elapsedTime; }
protected override IProjectContextInfo?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options) { NuGetProjectKind projectKind = NuGetProjectKind.Unknown; ProjectStyle projectStyle = ProjectStyle.Unknown; string? projectId = null; int propertyCount = reader.ReadMapHeader(); for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++) { switch (reader.ReadString()) { case ProjectIdPropertyName: projectId = reader.ReadString(); break; case ProjectKindPropertyName: projectKind = options.Resolver.GetFormatter <NuGetProjectKind>().Deserialize(ref reader, options); break; case ProjectStylePropertyName: projectStyle = options.Resolver.GetFormatter <ProjectStyle>().Deserialize(ref reader, options); break; default: reader.Skip(); break; } } Assumes.NotNull(projectId); return(new ProjectContextInfo(projectId, projectStyle, projectKind)); }
/// <summary> /// Create a library for a project. /// </summary> public static LockFileTargetLibrary CreateLockFileTargetProject( GraphItem <RemoteResolveResult> graphItem, LibraryIdentity library, LibraryIncludeFlags dependencyType, RestoreTargetGraph targetGraph, ProjectStyle rootProjectStyle) { return(CreateLockFileTargetProject(graphItem, library, dependencyType, targetGraph, rootProjectStyle, maccatalystFallback: null)); }
public BaselineProject(UnconfiguredProject project, ImmutableArray <string> globalProperties, ProjectStyle projectStyle, ProjectOutputType outputType, string candidateTargetTFM, bool keepCurrentTFMs) : this() { GlobalProperties = globalProperties; Project = project ?? throw new ArgumentNullException(nameof(project)); ProjectStyle = projectStyle; OutputType = outputType; TargetTFM = keepCurrentTFMs ? GetCurrentTFM(globalProperties, project) : AdjustTargetTFM(projectStyle, outputType, candidateTargetTFM); }
static bool CanCachePackageSpec(PackageSpec packageSpec) { if (packageSpec.RestoreMetadata == null) { return(false); } ProjectStyle style = packageSpec.RestoreMetadata.ProjectStyle; return(style == ProjectStyle.PackageReference || style == ProjectStyle.ProjectJson || style == ProjectStyle.PackagesConfig); }
public void HashCode_WithProjectStyle(ProjectStyle left, ProjectStyle right, bool expected) { var leftSide = new ProjectRestoreMetadata { ProjectStyle = left }; var rightSide = new ProjectRestoreMetadata { ProjectStyle = right }; AssertHashCode(expected, leftSide, rightSide); }
public void Equals_WithProjectStyle(ProjectStyle left, ProjectStyle right, bool expected) { var leftSide = new ProjectRestoreMetadata { ProjectStyle = left }; var rightSide = new ProjectRestoreMetadata { ProjectStyle = right }; AssertEquality(expected, leftSide, rightSide); }
private static string AdjustTargetTFM(ProjectStyle projectStyle, ProjectOutputType outputType, string candidateTargetTFM) { if (candidateTargetTFM.ContainsIgnoreCase(MSBuildFacts.Net5) && projectStyle is ProjectStyle.WindowsDesktop) { return(MSBuildFacts.Net5Windows); } if (projectStyle is not ProjectStyle.MSTest && outputType is ProjectOutputType.Library) { return(MSBuildFacts.NetStandard20); } return(candidateTargetTFM); }
public static ValueTask <IProjectContextInfo> CreateAsync(NuGetProject nugetProject, CancellationToken cancellationToken) { Assumes.NotNull(nugetProject); if (!nugetProject.TryGetMetadata(NuGetProjectMetadataKeys.ProjectId, out string projectId)) { throw new InvalidOperationException(); } NuGetProjectKind projectKind = GetProjectKind(nugetProject); ProjectStyle projectStyle = nugetProject.ProjectStyle; return(new ValueTask <IProjectContextInfo>(new ProjectContextInfo(projectId, projectStyle, projectKind))); }
public IProjectContextInfo?Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(null); } // stack overflow mitigation - see https://github.com/neuecc/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf options.Security.DepthStep(ref reader); try { NuGetProjectKind projectKind = NuGetProjectKind.Unknown; ProjectStyle projectStyle = ProjectStyle.Unknown; string? projectId = null; int propertyCount = reader.ReadMapHeader(); for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++) { switch (reader.ReadString()) { case ProjectIdPropertyName: projectId = reader.ReadString(); break; case ProjectKindPropertyName: projectKind = options.Resolver.GetFormatter <NuGetProjectKind>().Deserialize(ref reader, options); break; case ProjectStylePropertyName: projectStyle = options.Resolver.GetFormatter <ProjectStyle>().Deserialize(ref reader, options); break; default: reader.Skip(); break; } } Assumes.NotNull(projectId); return(new ProjectContextInfo(projectId, projectStyle, projectKind)); } finally { // stack overflow mitigation - see https://github.com/neuecc/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf reader.Depth--; } }
public HashSet <PackageReferenceInfo> LoadPackageReferences(IEnumerable <ProjectAnalyzer> projects) { var results = new HashSet <PackageReferenceInfo>(); foreach (var project in projects) { _ui.ReportMedium(() => $"Checking package references: {Path.GetFileName(project.ProjectFile.Path)}"); var projectStyle = ProjectStyle.Create(_ui, project); var projectPackages = projectStyle.LoadPackageReferences(); results.UnionWith(projectPackages); } return(results); }
public RestoreResult( bool success, IEnumerable <RestoreTargetGraph> restoreGraphs, IEnumerable <CompatibilityCheckResult> compatibilityCheckResults, IEnumerable <MSBuildOutputFile> msbuildFiles, LockFile lockFile, LockFile previousLockFile, string lockFilePath, ProjectStyle projectStyle, TimeSpan elapsedTime) { Success = success; RestoreGraphs = restoreGraphs; CompatibilityCheckResults = compatibilityCheckResults; MSBuildOutputFiles = msbuildFiles; LockFile = lockFile; LockFilePath = lockFilePath; PreviousLockFile = previousLockFile; ProjectStyle = projectStyle; ElapsedTime = elapsedTime; }
public override bool Execute() { var log = new MSBuildLogger(Log); // Log Inputs BuildTasksUtility.LogInputParam(log, nameof(HasPackageReferenceItems), HasPackageReferenceItems.ToString()); BuildTasksUtility.LogInputParam(log, nameof(MSBuildProjectDirectory), MSBuildProjectDirectory); BuildTasksUtility.LogInputParam(log, nameof(MSBuildProjectName), MSBuildProjectName); BuildTasksUtility.LogInputParam(log, nameof(ProjectJsonPath), ProjectJsonPath); BuildTasksUtility.LogInputParam(log, nameof(RestoreProjectStyle), RestoreProjectStyle); var result = BuildTasksUtility.GetProjectRestoreStyle(RestoreProjectStyle, HasPackageReferenceItems, ProjectJsonPath, MSBuildProjectDirectory, MSBuildProjectName, log); IsPackageReferenceCompatibleProjectStyle = result.IsPackageReferenceCompatibleProjectStyle; ProjectStyle = result.ProjectStyle; // Log Outputs BuildTasksUtility.LogOutputParam(log, nameof(IsPackageReferenceCompatibleProjectStyle), IsPackageReferenceCompatibleProjectStyle.ToString()); BuildTasksUtility.LogOutputParam(log, nameof(ProjectStyle), ProjectStyle.ToString()); return(!Log.HasLoggedErrors); }
private static IEnumerable <TargetFrameworkInformation> GetTargetFrameworkInformation(string filePath, ProjectStyle restoreType, IEnumerable <IMSBuildItem> items) { var uniqueIds = new HashSet <string>(); foreach (var item in GetItemByType(items, "TargetFrameworkInformation")) { var frameworkString = item.GetProperty("TargetFramework"); var targetFrameworkMoniker = item.GetProperty("TargetFrameworkMoniker"); var targetPlatforMoniker = item.GetProperty("TargetPlatformMoniker"); var targetPlatformMinVersion = item.GetProperty("TargetPlatformMinVersion"); var clrSupport = item.GetProperty("CLRSupport"); var targetAlias = string.IsNullOrEmpty(frameworkString) ? string.Empty : frameworkString; if (uniqueIds.Contains(targetAlias)) { continue; } uniqueIds.Add(targetAlias); NuGetFramework targetFramework = MSBuildProjectFrameworkUtility.GetProjectFramework( projectFilePath: filePath, targetFrameworkMoniker: targetFrameworkMoniker, targetPlatformMoniker: targetPlatforMoniker, targetPlatformMinVersion: targetPlatformMinVersion, clrSupport: clrSupport); var targetFrameworkInfo = new TargetFrameworkInformation() { FrameworkName = targetFramework, TargetAlias = targetAlias }; if (restoreType == ProjectStyle.PackageReference || restoreType == ProjectStyle.Standalone || restoreType == ProjectStyle.DotnetToolReference) { var packageTargetFallback = MSBuildStringUtility.Split(item.GetProperty("PackageTargetFallback")) .Select(NuGetFramework.Parse) .ToList(); var assetTargetFallback = MSBuildStringUtility.Split(item.GetProperty(AssetTargetFallbackUtility.AssetTargetFallback)) .Select(NuGetFramework.Parse) .ToList(); // Throw if an invalid combination was used. AssetTargetFallbackUtility.EnsureValidFallback(packageTargetFallback, assetTargetFallback, filePath); // Update the framework appropriately AssetTargetFallbackUtility.ApplyFramework(targetFrameworkInfo, packageTargetFallback, assetTargetFallback); targetFrameworkInfo.RuntimeIdentifierGraphPath = item.GetProperty("RuntimeIdentifierGraphPath"); } yield return(targetFrameworkInfo); } }
/// <summary> /// Convert MSBuild items to a PackageSpec. /// </summary> public static PackageSpec GetPackageSpec(IEnumerable <IMSBuildItem> items) { if (items == null) { throw new ArgumentNullException(nameof(items)); } PackageSpec result = null; // There should only be one ProjectSpec per project in the item set, // but if multiple do appear take only the first one in an effort // to handle this gracefully. var specItem = GetItemByType(items, "projectSpec").FirstOrDefault(); if (specItem != null) { ProjectStyle restoreType = GetProjectStyle(specItem); bool isCpvmEnabled = IsCentralVersionsManagementEnabled(specItem, restoreType); // Get base spec if (restoreType == ProjectStyle.ProjectJson) { result = GetProjectJsonSpec(specItem); } else { // Read msbuild data for PR and related projects result = GetBaseSpec(specItem, restoreType, items); } // Applies to all types result.RestoreMetadata.ProjectStyle = restoreType; result.RestoreMetadata.ProjectPath = specItem.GetProperty("ProjectPath"); result.RestoreMetadata.ProjectUniqueName = specItem.GetProperty("ProjectUniqueName"); if (string.IsNullOrEmpty(result.Name)) { result.Name = result.RestoreMetadata.ProjectName ?? result.RestoreMetadata.ProjectUniqueName ?? Path.GetFileNameWithoutExtension(result.FilePath); } // Read project references for all AddProjectReferences(result, items); if (restoreType == ProjectStyle.PackageReference || restoreType == ProjectStyle.Standalone || restoreType == ProjectStyle.DotnetCliTool || restoreType == ProjectStyle.ProjectJson || restoreType == ProjectStyle.DotnetToolReference || restoreType == ProjectStyle.PackagesConfig) { foreach (var source in MSBuildStringUtility.Split(specItem.GetProperty("Sources"))) { // Fix slashes incorrectly removed by MSBuild var pkgSource = new PackageSource(FixSourcePath(source)); result.RestoreMetadata.Sources.Add(pkgSource); } foreach (var configFilePath in MSBuildStringUtility.Split(specItem.GetProperty("ConfigFilePaths"))) { result.RestoreMetadata.ConfigFilePaths.Add(configFilePath); } foreach (var folder in MSBuildStringUtility.Split(specItem.GetProperty("FallbackFolders"))) { result.RestoreMetadata.FallbackFolders.Add(folder); } result.RestoreMetadata.PackagesPath = specItem.GetProperty("PackagesPath"); result.RestoreMetadata.OutputPath = specItem.GetProperty("OutputPath"); } // Read package references for netcore, tools, and standalone if (restoreType == ProjectStyle.PackageReference || restoreType == ProjectStyle.Standalone || restoreType == ProjectStyle.DotnetCliTool || restoreType == ProjectStyle.DotnetToolReference) { AddPackageReferences(result, items, isCpvmEnabled); AddPackageDownloads(result, items); AddFrameworkReferences(result, items); // Store the original framework strings for msbuild conditionals result.TargetFrameworks.ForEach(tfi => result.RestoreMetadata.OriginalTargetFrameworks.Add( !string.IsNullOrEmpty(tfi.TargetAlias) ? tfi.TargetAlias : tfi.FrameworkName.GetShortFolderName())); } if (restoreType == ProjectStyle.PackageReference || restoreType == ProjectStyle.Standalone || restoreType == ProjectStyle.DotnetToolReference) { // Set project version result.Version = GetVersion(specItem); // Add RIDs and Supports result.RuntimeGraph = GetRuntimeGraph(specItem); // Add CrossTargeting flag result.RestoreMetadata.CrossTargeting = IsPropertyTrue(specItem, "CrossTargeting"); // Add RestoreLegacyPackagesDirectory flag result.RestoreMetadata.LegacyPackagesDirectory = IsPropertyTrue( specItem, "RestoreLegacyPackagesDirectory"); // ValidateRuntimeAssets compat check result.RestoreMetadata.ValidateRuntimeAssets = IsPropertyTrue(specItem, "ValidateRuntimeAssets"); // True for .NETCore projects. result.RestoreMetadata.SkipContentFileWrite = IsPropertyTrue(specItem, "SkipContentFileWrite"); // Warning properties result.RestoreMetadata.ProjectWideWarningProperties = GetWarningProperties(specItem); // Packages lock file properties result.RestoreMetadata.RestoreLockProperties = GetRestoreLockProperites(specItem); } if (restoreType == ProjectStyle.PackagesConfig) { var pcRestoreMetadata = (PackagesConfigProjectRestoreMetadata)result.RestoreMetadata; // Packages lock file properties pcRestoreMetadata.PackagesConfigPath = specItem.GetProperty("PackagesConfigPath"); pcRestoreMetadata.RepositoryPath = specItem.GetProperty("RepositoryPath"); var solutionDir = specItem.GetProperty("SolutionDir"); if (string.IsNullOrEmpty(pcRestoreMetadata.RepositoryPath) && !string.IsNullOrEmpty(solutionDir) && solutionDir != "*Undefined*") { pcRestoreMetadata.RepositoryPath = Path.Combine( solutionDir, "packages" ); } pcRestoreMetadata.RestoreLockProperties = GetRestoreLockProperites(specItem); } if (restoreType == ProjectStyle.ProjectJson) { // Check runtime assets by default for project.json result.RestoreMetadata.ValidateRuntimeAssets = true; } result.RestoreMetadata.CentralPackageVersionsEnabled = isCpvmEnabled; } return(result); }
internal static bool IsCentralVersionsManagementEnabled(IMSBuildItem projectSpecItem, ProjectStyle projectStyle) { return(IsPropertyTrue(projectSpecItem, "_CentralPackageVersionsEnabled") && projectStyle == ProjectStyle.PackageReference); }
public NoOpRestoreResult(bool success, string lockFilePath, Lazy <LockFile> lockFileLazy, CacheFile cacheFile, string cacheFilePath, ProjectStyle projectStyle, TimeSpan elapsedTime) : base(success: success, restoreGraphs: null, compatibilityCheckResults: new List <CompatibilityCheckResult>(), msbuildFiles: null, lockFile: null, previousLockFile: null, lockFilePath: lockFilePath, cacheFile: cacheFile, cacheFilePath: cacheFilePath, packagesLockFilePath: null, packagesLockFile: null, dependencyGraphSpecFilePath: null, dependencyGraphSpec: null, projectStyle: projectStyle, elapsedTime: elapsedTime) { _lockFileLazy = lockFileLazy ?? throw new ArgumentNullException(nameof(lockFileLazy)); }