Ejemplo n.º 1
0
 public void RemoveProperty(MSBuildProperty prop)
 {
     if (properties != null)
     {
         properties.Remove(prop.Name);
         propertyList.Remove(prop);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Get hover content for an <see cref="MSBuildProperty"/>.
        /// </summary>
        /// <param name="property">
        ///     The <see cref="MSBuildProperty"/>.
        /// </param>
        /// <returns>
        ///     The content, or <c>null</c> if no content is provided.
        /// </returns>
        public MarkedStringContainer Property(MSBuildProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            List <MarkedString> content = new List <MarkedString>
            {
                $"Property: `{property.Name}`"
            };

            string propertyHelp = MSBuildSchemaHelp.ForProperty(property.Name);

            if (propertyHelp != null)
            {
                content.Add(propertyHelp);
            }

            if (property.IsOverridden)
            {
                Position overridingDeclarationPosition = property.DeclaringXml.Location.ToNative();

                StringBuilder overrideDescription = new StringBuilder();
                string        declarationFile     = property.DeclaringXml.Location.File;
                if (declarationFile != property.Property.Xml.Location.File)
                {
                    Uri declarationDocumentUri = VSCodeDocumentUri.FromFileSystemPath(declarationFile);
                    overrideDescription.AppendLine(
                        $"Value overridden at {overridingDeclarationPosition} in [{Path.GetFileName(declarationFile)}]({declarationDocumentUri})."
                        );
                }
                else
                {
                    overrideDescription.AppendLine($"Value overridden at {overridingDeclarationPosition} in this file.");
                }

                overrideDescription.AppendLine();
                overrideDescription.AppendLine();
                overrideDescription.AppendLine(
                    $"Unused value: `{property.DeclaringXml.Value}`"
                    );
                overrideDescription.AppendLine();
                overrideDescription.AppendLine(
                    $"Actual value: `{property.Value}`"
                    );

                content.Add(overrideDescription.ToString());
            }
            else
            {
                content.Add($"Value: `{property.Value}`");
            }

            return(new MarkedStringContainer(content));
        }
Ejemplo n.º 3
0
        public bool RemoveProperty(string name)
        {
            MSBuildProperty prop = (MSBuildProperty)GetProperty(name);

            if (prop != null)
            {
                RemoveProperty(prop);
                return(true);
            }
            return(false);
        }
        /// <summary>
        ///     Get hover content for an <see cref="MSBuildProperty"/>.
        /// </summary>
        /// <param name="property">
        ///     The <see cref="MSBuildProperty"/>.
        /// </param>
        /// <returns>
        ///     The content, or <c>null</c> if no content is provided.
        /// </returns>
        public MarkedStringContainer Property(MSBuildProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            List <MarkedString> content = new List <MarkedString>
            {
                $"Property: `{property.Name}`"
            };

            string propertyHelp = MSBuildSchemaHelp.ForProperty(property.Name);

            if (propertyHelp != null)
            {
                content.Add(propertyHelp);
            }

            if (property.IsOverridden)
            {
                // BUG: This is the location of the *overridden* property, not the *overriding* property.
                //      We'll need to build a lookup by recursively following ProjectProperty.Predecessor.
                Position overridingDeclarationPosition = property.DeclaringXml.Location.ToNative();

                StringBuilder overrideDescription = new StringBuilder();
                string        declarationFile     = property.DeclaringXml.Location.File;
                if (declarationFile != property.Property.Xml.Location.File)
                {
                    Uri declarationDocumentUri = VSCodeDocumentUri.FromFileSystemPath(declarationFile);
                    overrideDescription.AppendLine(
                        $"Value overridden at {overridingDeclarationPosition} in [{Path.GetFileName(declarationFile)}]({declarationDocumentUri})."
                        );
                }
                else
                {
                    overrideDescription.AppendLine($"Value overridden at {overridingDeclarationPosition} in this file.");
                }

                overrideDescription.AppendLine();
                overrideDescription.AppendLine();
                overrideDescription.AppendLine(
                    $"Unused value: `{property.DeclaringXml.Value}`"
                    );
                overrideDescription.AppendLine();
                overrideDescription.AppendLine(
                    $"Actual value: `{property.Value}`"
                    );

                content.Add(overrideDescription.ToString());
            }
            else
            {
                content.Add($"Value: `{property.Value}`");
            }

            string helpLink = MSBuildSchemaHelp.HelpLinkForProperty(property.Name);

            if (!String.IsNullOrWhiteSpace(helpLink))
            {
                content.Add(
                    $"[Help]({helpLink})"
                    );
            }

            return(new MarkedStringContainer(content));
        }
Ejemplo n.º 5
0
        private async Task <ImmutableArray <ILRepackData> > GetMergeFilesAsync(FileInfo projectFile)
        {
// ReSharper disable PossibleNullReferenceException
            DirectoryInfo binDirectory = projectFile.Directory.GetDirectories("bin").SingleOrDefault();

            // ReSharper restore PossibleNullReferenceException

            if (binDirectory == null)
            {
                return(ImmutableArray <ILRepackData> .Empty);
            }

            string configuration = "release"; // TODO support ilmerge for debug

            DirectoryInfo releaseDir = binDirectory.GetDirectories(configuration).SingleOrDefault();

            if (releaseDir is null)
            {
                _logger.WriteWarning(
                    $"The release directory '{Path.Combine(binDirectory.FullName, configuration)}' does not exist");
                return(ImmutableArray <ILRepackData> .Empty);
            }

            DirectoryInfo[] releasePlatformDirectories = releaseDir.GetDirectories();

            if (releasePlatformDirectories.Length > 1)
            {
                _logger.WriteWarning(
                    $"Multiple release directories were found for  '{Path.Combine(binDirectory.FullName, configuration)}'");
                return(ImmutableArray <ILRepackData> .Empty);
            }

            string NormalizeVersion(string value)
            {
                if (value.StartsWith("v", StringComparison.OrdinalIgnoreCase))
                {
                    return(value.Substring(1));
                }

                return(value);
            }

            string targetFrameworkVersionValue;

            DirectoryInfo releasePlatformDirectory;

            if (IsNetSdkProject(projectFile))
            {
                _logger.WriteWarning(
                    $"Microsoft.NET.Sdk projects are in progress supported '{Path.Combine(binDirectory.FullName, configuration)}'");

                targetFrameworkVersionValue = string.Empty;

                if (!releasePlatformDirectories.Any())
                {
                    _logger.WriteWarning(
                        $"No release platform directories were found in '{Path.Combine(binDirectory.FullName, configuration)}'");
                    return(ImmutableArray <ILRepackData> .Empty);
                }

                List <string> args = new List <string>
                {
                    "publish",
                    projectFile.FullName,
                    $"/p:configuration={configuration}"
                };

                ExitCode exitCode = await ProcessHelper.ExecuteAsync(
                    Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "dotnet", "dotnet.exe"),
                    args,
                    _logger);

                if (!exitCode.IsSuccess)
                {
                    _logger.WriteWarning($"Could not publish project {projectFile.FullName}");
                    return(ImmutableArray <ILRepackData> .Empty);
                }

                DirectoryInfo platformDirectory = releasePlatformDirectories.Single();

                DirectoryInfo publishDirectoryInfo = platformDirectory.GetDirectories("publish").SingleOrDefault();

                if (publishDirectoryInfo is null)
                {
                    _logger.WriteWarning($"The publish directory '{Path.Combine(platformDirectory.FullName, "publish")}' does not exist");
                    return(ImmutableArray <ILRepackData> .Empty);
                }

                releasePlatformDirectory = publishDirectoryInfo;
            }
            else
            {
                CsProjFile csProjFile = CsProjFile.LoadFrom(projectFile.FullName);

                const string targetFrameworkVersion = "TargetFrameworkVersion";

                MSBuildProperty msBuildProperty = csProjFile.BuildProject.PropertyGroups
                                                  .SelectMany(group =>
                                                              group.Properties.Where(
                                                                  property => property.Name.Equals(
                                                                      targetFrameworkVersion,
                                                                      StringComparison.OrdinalIgnoreCase)))
                                                  .FirstOrDefault();

                if (string.IsNullOrWhiteSpace(msBuildProperty?.Value))
                {
                    throw new InvalidOperationException(
                              $"The CSProj file '{csProjFile.FileName}' does not contain a property '{targetFrameworkVersion}");
                }

                targetFrameworkVersionValue = NormalizeVersion(msBuildProperty.Value);

                releasePlatformDirectory = releaseDir;
            }

            List <FileInfo> exes = releasePlatformDirectory
                                   .EnumerateFiles("*.exe")
                                   .Where(FileIsStandAloneExe)
                                   .ToList();

            if (exes.Count > 1)
            {
                throw new InvalidOperationException(
                          $"Only one exe can be merged, found {string.Join(", ", exes.Select(file => file.FullName))}");
            }

            if (!exes.Any())
            {
                throw new InvalidOperationException("Could not find any exe files to merge");
            }

            FileInfo exe = exes.Single();

            string platform = GetPlatform(exe);

            ImmutableArray <FileInfo> dlls = releasePlatformDirectory
                                             .EnumerateFiles("*.dll")
                                             .Where(FileIsStandAloneExe)
                                             .ToImmutableArray();

            ImmutableArray <ILRepackData> mergeFiles =
                new[] { new ILRepackData(exe.FullName, dlls, configuration, platform, targetFrameworkVersionValue) }
            .ToImmutableArray();

            return(mergeFiles);
        }
Ejemplo n.º 6
0
        private IEnumerable <ILRepackData> GetIlMergeFiles(FileInfo projectFile)
        {
// ReSharper disable PossibleNullReferenceException
            DirectoryInfo binDirectory = projectFile.Directory.GetDirectories("bin").SingleOrDefault();

            // ReSharper restore PossibleNullReferenceException

            if (binDirectory == null)
            {
                yield break;
            }

            string configuration = "release"; // TODO support ilmerge for debug

            DirectoryInfo releaseDir = binDirectory.GetDirectories(configuration).SingleOrDefault();

            if (releaseDir == null)
            {
                _logger.WriteWarning(
                    $"A release directory '{Path.Combine(binDirectory.FullName, configuration)}' was not found");
                yield break;
            }

            CsProjFile csProjFile = CsProjFile.LoadFrom(projectFile.FullName);

            const string targetFrameworkVersion = "TargetFrameworkVersion";

            MSBuildProperty msBuildProperty = csProjFile.BuildProject.PropertyGroups.SelectMany(
                group =>
                group.Properties.Where(
                    property => property.Name.Equals(
                        targetFrameworkVersion,
                        StringComparison.OrdinalIgnoreCase)))
                                              .FirstOrDefault();

            if (string.IsNullOrWhiteSpace(msBuildProperty?.Value))
            {
                throw new InvalidOperationException(
                          $"The CSProj file '{csProjFile.FileName}' does not contain a property '{targetFrameworkVersion}");
            }

            List <FileInfo> exes = releaseDir
                                   .EnumerateFiles("*.exe")
                                   .Where(FileIsStandAloneExe)
                                   .ToList();

            if (exes.Count != 1)
            {
                throw new InvalidOperationException("Only one exe can be ILMerged");
            }

            FileInfo exe = exes.Single();

            string platform = GetPlatform(exe);

            ImmutableArray <FileInfo> dlls = releaseDir
                                             .EnumerateFiles("*.dll")
                                             .Where(FileIsStandAloneExe)
                                             .ToImmutableArray();

            string NormalizeVersion(string value)
            {
                if (value.StartsWith("v", StringComparison.OrdinalIgnoreCase))
                {
                    return(value.Substring(1));
                }

                return(value);
            }

            string targetFrameworkVersionValue = NormalizeVersion(msBuildProperty.Value);

            yield return(new ILRepackData(exe.FullName, dlls, configuration, platform, targetFrameworkVersionValue));
        }
Ejemplo n.º 7
0
        public void TestConstructor_GivenNullValueSetsValueToEmpty()
        {
            var objectUnderTest = new MSBuildProperty(DefaultPropertyName, null);

            Assert.AreEqual("", objectUnderTest.PropertyValue);
        }
Ejemplo n.º 8
0
        public void TestToString_ReturnsMSBuildCliArg()
        {
            var objectUnderTest = new MSBuildProperty(ExpectedPropertyName, ExpectedPropertyValue);

            Assert.AreEqual("/p:ExpectedPropertyName=\"Expected Property Value\"", objectUnderTest.ToString());
        }
Ejemplo n.º 9
0
        public void TestConstructor_SetsPropertyValue()
        {
            var objectUnderTest = new MSBuildProperty(DefaultPropertyName, ExpectedPropertyValue);

            Assert.AreEqual(ExpectedPropertyValue, objectUnderTest.PropertyValue);
        }