public PackageVersionVariable Update(string variableName, string version)
        {
            if (!_versionVariables.TryGetValue(variableName, out var variable))
            {
                var element = _document.CreatePropertyElement(variableName);
                variable = new PackageVersionVariable(element, version, isReadOnly: false);
                _versionVariables[variableName] = variable;
                variable.AddToGroup(_autoPackageVersions);
            }

            variable.UpdateVersion(version);
            return(variable);
        }
Exemplo n.º 2
0
        public override ProjectPropertyElement ConditionallyTransform(T source)
        {
            string propertyValue = GetPropertyValue(source);

            var property = _propertyObjectGenerator.CreatePropertyElement(PropertyName);

            property.Value = propertyValue;

            return(property);
        }
 public ProjectPropertyElement Set(string variableName, string version)
 {
     _versionVariables[variableName] = version;
     if (!_versionElements.TryGetValue(variableName, out var element))
     {
         element = _document.CreatePropertyElement(variableName);
         _versionElements.Add(variableName, element);
     }
     element.Value = version;
     return(element);
 }
        void AddPropertyWithCondition(ProjectRootElement projectRoot, string name, string value, string condition)
        {
            ProjectPropertyGroupElement groupProperty = projectRoot.CreatePropertyGroupElement();

            groupProperty.Condition = condition;
            projectRoot.AppendChild(groupProperty);

            ProjectPropertyElement property = projectRoot.CreatePropertyElement(name);

            groupProperty.AppendChild(property);
            property.Value     = value;
            property.Condition = condition;
        }
Exemplo n.º 5
0
        private void AddTargetFrameworkProperty()
        {
            var propGroup = _projectRootElement.PropertyGroups.FirstOrDefault(pg => pg.Condition == "");

            if (propGroup == null)
            {
                propGroup = _projectRootElement.AddPropertyGroup();
            }

            var targetFrameworkElement = _projectRootElement.CreatePropertyElement("TargetFramework");

            targetFrameworkElement.Value = _sdkBaselineProject.Project.FirstConfiguredProject.GetProperty("TargetFramework").EvaluatedValue;
            propGroup.PrependChild(targetFrameworkElement);
        }
Exemplo n.º 6
0
        public override ProjectPropertyElement ConditionallyTransform(T source)
        {
            string propertyValue = GetPropertyValue(source);

            var property = _propertyObjectGenerator.CreatePropertyElement(PropertyName);

            property.Value = propertyValue;

            if (!string.IsNullOrEmpty(_msbuildCondition))
            {
                property.Condition = _msbuildCondition;
            }

            return(property);
        }
Exemplo n.º 7
0
        private void Parse(bool includeHiddenItems = false)
        {
            var stream              = File.OpenRead(projectFileName);
            var reader              = XmlReader.Create(stream);
            var cache               = s_ProjectRootElementCache.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).First().Invoke(new object[] { true });
            var fileInfo            = new FileInfo(projectFileName);
            var addPropertyElements = new List <VSProjectProperty>();

            this.includeHiddenItems = includeHiddenItems;

            this.Hash = fileInfo.GetHash();

            if (s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Any(c => c.GetParameters().Count() == 4 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache"))
            {
                rootElement = (ProjectRootElement)s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Where(c => c.GetParameters().Count() >= 2 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache").First().Invoke(new object[] { reader, cache, true, true });
            }
            else if (s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Any(c => c.GetParameters().Count() == 2 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache"))
            {
                rootElement = (ProjectRootElement)s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Where(c => c.GetParameters().Count() == 2 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache").First().Invoke(new object[] { reader, cache });
            }
            else
            {
                throw new Exception("Unable to find constructor in ProjectRootElementCache for VSProject parser");
            }

            if (rootElement.Properties.Count(p => p.Name == "AssemblyName") == 1)
            {
                var assemblyName = rootElement.Properties.SingleOrDefault(p => p.Name == "AssemblyName");
                ProjectPropertyElement outputPathElement;

                if (assemblyName != null)
                {
                    var    configuration            = rootElement.Properties.Single(p2 => p2.Name == "Configuration").Value;
                    var    platform                 = rootElement.Properties.SingleOrDefault(p2 => p2.Name == "Platform");
                    var    isSilverlightAppProperty = rootElement.Properties.SingleOrDefault(p2 => p2.Name == "SilverlightApplication");
                    string platformValue            = string.Empty;

                    if (this.name == null)
                    {
                        this.name = assemblyName.Value;
                    }

                    if (isSilverlightAppProperty != null)
                    {
                        IsSilverlightApplication = bool.Parse(isSilverlightAppProperty.Value);

                        if (IsSilverlightApplication)
                        {
                            var xapFileNameProperty = rootElement.Properties.SingleOrDefault(p2 => p2.Name == "XapFilename");

                            if (xapFileNameProperty != null)
                            {
                                XAPFilename = xapFileNameProperty.Value;
                            }
                        }
                    }

                    if (platform == null)
                    {
                        platformValue = rootElement.Properties.First(p2 => p2.Name == "PlatformTarget").Value;
                    }
                    else
                    {
                        platformValue = platform.Value;
                    }

                    outputPathElement = rootElement.Properties.SingleOrDefault(p =>
                    {
                        if (p.Name == "OutputPath")
                        {
                            var condition = Regex.Replace(p.Parent.Condition, @"\s", "");

                            if (condition == string.Format("'$(Configuration)|$(Platform)'=='{0}|{1}'", configuration, platformValue))
                            {
                                return(true);
                            }
                            else if (platformValue == "AnyCPU")
                            {
                                var pattern = string.Format(@"'\$\(Configuration\)\|\$\(Platform\)'=='{0}\|\w+?'", configuration);

                                return(Regex.IsMatch(condition, pattern));
                            }

                            return(false);
                        }
                        else
                        {
                            return(false);
                        }
                    });

                    if (outputPathElement != null)
                    {
                        OutputPath = outputPathElement.Value;
                    }

                    var    outputType = rootElement.Properties.SingleOrDefault(p => p.Name == "OutputType").Value;
                    string outputExt  = string.Empty;

                    switch (outputType)
                    {
                    case "Library":
                        outputExt = ".dll";
                        break;

                    case "Exe":
                        outputExt = ".exe";
                        break;

                    case "WinExe":
                        outputExt = ".exe";
                        break;

                    default:
                        Debugger.Break();
                        break;
                    }

                    if (OutputPath != null)
                    {
                        var directory = new FileInfo(this.projectFileName).DirectoryName;

                        this.OutputFile = Path.GetFullPath(Path.Combine(directory, OutputPath, assemblyName.Value + outputExt));
                    }
                }
            }
            else
            {
                var targetFramework = rootElement.Properties.SingleOrDefault(p => p.Name == "TargetFramework");
                var directory       = new FileInfo(this.projectFileName).DirectoryName;
                var outputDirectory = new DirectoryInfo(Path.Combine(directory, $"bin\\Debug\\{ targetFramework.Value }"));
                ProjectPropertyElement propertyElement;

                // kn todo - assuming debug and dll

                this.name       = Path.GetFileNameWithoutExtension(projectFileName);
                this.OutputPath = outputDirectory.FullName;
                this.OutputFile = Path.Combine(outputDirectory.FullName, this.name + ".dll");

                propertyElement = rootElement.CreatePropertyElement("RootNamespace");

                propertyElement.Value = this.name;

                addPropertyElements.Add(new VSProjectProperty(this, propertyElement));

                Debug.WriteLine("Project '{0}' has either zero or more than one assembly output section.  Assembly related properties will be indeterminant and set to null.", this.Name);
            }

            rootElementContainer = (ProjectElementContainer)rootElement;

            stream.Close();

            itemCollection = (ICollection)s_ProjectRootElement_Items.GetValue(rootElement, null);

            if (!loadOnDemand)
            {
                // will force the iteration

                GetProperties().ToList();
                GetItems().ToList();

                foreach (var properyElement in addPropertyElements)
                {
                    properties.Add(properyElement);
                }
            }
        }