private static string GetItemMetadataValueOrDefault(
            MSBuildProjectItemData item, string propertyName, string defaultValue = "")
        {
            if (item.Metadata.TryGetValue(propertyName, out var propertyValue))
            {
                return(propertyValue);
            }

            return(defaultValue);
        }
Example #2
0
        private static string GetPropertyValueOrDefault(
            MSBuildProjectItemData item, string propertyName, string defaultValue = "")
        {
            if (item.Metadata.Keys.Contains(propertyName))
            {
                return(item.Metadata[propertyName]);
            }

            return(defaultValue);
        }
        private static VersionRange GetVersionRange(MSBuildProjectItemData item)
        {
            var versionRange = GetItemMetadataValueOrDefault(item, ProjectBuildProperties.Version);

            if (!string.IsNullOrEmpty(versionRange))
            {
                return(VersionRange.Parse(versionRange));
            }

            return(VersionRange.All);
        }
        private static LibraryDependency ToPackageLibraryDependency(MSBuildProjectItemData item)
        {
            var dependency = new LibraryDependency
            {
                LibraryRange = new LibraryRange(
                    name: item.EvaluatedInclude,
                    versionRange: GetVersionRange(item),
                    typeConstraint: LibraryDependencyTarget.Package)
            };

            MSBuildRestoreUtility.ApplyIncludeFlags(
                dependency,
                GetItemMetadataValueOrDefault(item, ProjectItemProperties.IncludeAssets),
                GetItemMetadataValueOrDefault(item, ProjectItemProperties.ExcludeAssets),
                GetItemMetadataValueOrDefault(item, ProjectItemProperties.PrivateAssets));

            return(dependency);
        }
Example #5
0
        private static ProjectRestoreReference ToProjectRestoreReference(MSBuildProjectItemData item, string projectDirectory)
        {
            var referencePath = Path.GetFullPath(
                Path.Combine(
                    projectDirectory, item.EvaluatedInclude));

            var reference = new ProjectRestoreReference()
            {
                ProjectUniqueName = referencePath,
                ProjectPath       = referencePath
            };

            MSBuildRestoreUtility.ApplyIncludeFlags(
                reference,
                includeAssets: GetPropertyValueOrDefault(item, IncludeAssets),
                excludeAssets: GetPropertyValueOrDefault(item, ExcludeAssets),
                privateAssets: GetPropertyValueOrDefault(item, PrivateAssets));

            return(reference);
        }