Ejemplo n.º 1
0
        private void ModifyAssemblyFileVersion(AssemblyInfoWriter writer, AssemblyInfoReader reader)
        {
            Log.LogMessage(MessageImportance.Normal,
                           string.Format("Modifying AssemblyFileVersion with pattern: {0}", AssemblyVersionPattern));

            try
            {
                string newValue = new PatternBasedParser().Replace(reader.GetAssemblyFileVersion(), AssemblyFileVersionPattern);

                writer.ModifyAssemblyFileVersionTo(newValue);
            }
            catch (ApplicationException exception)
            {
                Log.LogErrorFromException(exception);
            }
        }
        public void When_modifying_the_file_version_it_should_modify_it_and_save_it()
        {
            // ----------------------------------------------------------------
            // ARRANGE
            //-----------------------------------------------------------------
            string assemblyInfoFile = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\AssemblyInfo_1.txt";
            var parser = new AssemblyInfoWriter(assemblyInfoFile);

            // ----------------------------------------------------------------
            // ACT
            //-----------------------------------------------------------------
            parser.ModifyAssemblyFileVersionTo("2.2.2.2");

            // ----------------------------------------------------------------
            // ASSERT
            //-----------------------------------------------------------------
            bool parserReplacedValue = FindInFile(AssemblyInfoContext.FileVersionBeginText + "2.2.2.2" + AssemblyInfoContext.LastPartOfLine, assemblyInfoFile);

            Assert.IsTrue(parserReplacedValue);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start the task by calling it with MSBuild 
        /// </summary>
        public override bool Execute()
        {
            var reader = new AssemblyInfoReader(AssemblyInfoPath);
            var writer = new AssemblyInfoWriter(AssemblyInfoPath);

            if (!string.IsNullOrEmpty(AssemblyVersionPattern))
            {
                ModifyAssemblyVersion(writer, reader);
            }

            if (!string.IsNullOrEmpty(AssemblyFileVersionPattern))
            {
                ModifyAssemblyFileVersion(writer, reader);
            }

            if (!string.IsNullOrEmpty(AssemblyInformationalVersion))
            {
                ModifyAssemblyInformationalVersion(writer, reader);
            }

            return true;
        }
        public void When_the_file_is_set_to_readonly_it_should_still_modify_it()
        {
            // ----------------------------------------------------------------
            // ARRANGE
            //-----------------------------------------------------------------
            string assemblyInfoFile = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\ReadOnlyAssemblyInfo.txt";

            new FileInfo(assemblyInfoFile) {IsReadOnly = true};

            var parser = new AssemblyInfoWriter(assemblyInfoFile);

            // ----------------------------------------------------------------
            // ACT
            //-----------------------------------------------------------------
            parser.ModifyAssemblyFileVersionTo("2.2.2.2");
            parser.ModifyAssemblyVersionTo("1.1.1.1");

            // ----------------------------------------------------------------
            // ASSERT
            //-----------------------------------------------------------------
            bool parserReplacedAssemblyFileVersionValue = FindInFile(AssemblyInfoContext.FileVersionBeginText + "2.2.2.2" + AssemblyInfoContext.LastPartOfLine, assemblyInfoFile);
            bool parserReplacedAssemblyVersionValue = FindInFile(AssemblyInfoContext.InfoVersionBeginText + "1.1.1.1" + AssemblyInfoContext.LastPartOfLine, assemblyInfoFile);

            Assert.IsTrue(parserReplacedAssemblyFileVersionValue);
            Assert.IsTrue(parserReplacedAssemblyVersionValue);
            Assert.IsTrue(new FileInfo(assemblyInfoFile).IsReadOnly);
        }