Example #1
0
        public void Can_Set_All_Assembly_Version_Attributes_In_Files()
        {
            // Arrange
            const string productVersion = "1.2.0.0";
            const string version        = "1.2.3.4";

            var command =
                new SetVersionAttributesInFilesCommand
            {
                AssemblyFileVersion          = version,
                AssemblyInformationalVersion = productVersion,
                AssemblyVersion            = version,
                CommandLog                 = new ConsoleCommandLog(),
                CreateAttributeIfNotExists = true,
                DirectoryToSearch          = _directoryToSearch,
                FileNamesToSearch          = "AssemblyInfo*.cs",
                Recursive = true,
                WriteVerboseLogMessages = true
            };

            // Act
            var succeeded = command.Execute();

            // Assert
            succeeded.ShouldBeTrue();

            foreach (var filename in _testFilenames)
            {
                File.Exists(filename).ShouldBeTrue();

                var text = File.ReadAllText(filename);

                text.ShouldContain("[assembly: AssemblyVersion(\"1.2.3.4\")]");
                text.ShouldContain("[assembly: AssemblyFileVersion(\"1.2.3.4\")]");
                text.ShouldContain("[assembly: AssemblyInformationalVersion(\"1.2.0.0\")]");
            }
        }
        public void Can_Set_All_Assembly_Version_Attributes_In_Files()
        {
            // Arrange
            const string productVersion = "1.2.0.0";
            const string version = "1.2.3.4";

            var command =
                new SetVersionAttributesInFilesCommand
                {
                    AssemblyFileVersion = version,
                    AssemblyInformationalVersion = productVersion,
                    AssemblyVersion = version,
                    CommandLog = new ConsoleCommandLog(),
                    CreateAttributeIfNotExists = true,
                    DirectoryToSearch = _directoryToSearch,
                    FileNamesToSearch = "AssemblyInfo*.cs",
                    Recursive = true,
                    WriteVerboseLogMessages = true
                };

            // Act
            var succeeded = command.Execute();

            // Assert
            succeeded.ShouldBeTrue();

            foreach (var filename in _testFilenames)
            {
                File.Exists(filename).ShouldBeTrue();

                var text = File.ReadAllText(filename);

                text.ShouldContain("[assembly: AssemblyVersion(\"1.2.3.4\")]");
                text.ShouldContain("[assembly: AssemblyFileVersion(\"1.2.3.4\")]");
                text.ShouldContain("[assembly: AssemblyInformationalVersion(\"1.2.0.0\")]");
            }
        }
        /// <summary>
        /// When implemented in a derived class, performs the execution of the activity.
        /// </summary>
        /// <param name="context">The execution context under which the activity executes.</param>
        protected override void Execute(CodeActivityContext context)
        {
            var assemblyFileVersion = AssemblyFileVersion.Get(context);
            var assemblyInformationalVersion = AssemblyInformationalVersion.Get(context);
            var assemblyVersion = AssemblyVersion.Get(context);
            var createAttributeIfNotExists = CreateAttributeIfNotExists.Get(context);
            var directoryToSearch = DirectoryToSearch.Get(context);
            var fileNamesToSearch = FileNamesToSearch.Get(context);
            var commandLog = new CodeActivityContextCommandLog(context);
            var recursive = Recursive.Get(context);
            var writeVerboseLogMessages = WriteVerboseLogMessages.Get(context);

            var command =
                new SetVersionAttributesInFilesCommand
                {
                    AssemblyFileVersion = assemblyFileVersion,
                    AssemblyInformationalVersion = assemblyInformationalVersion,
                    AssemblyVersion = assemblyVersion,
                    CreateAttributeIfNotExists = createAttributeIfNotExists,
                    DirectoryToSearch = directoryToSearch,
                    FileNamesToSearch = fileNamesToSearch,
                    CommandLog = commandLog,
                    Recursive = recursive,
                    WriteVerboseLogMessages = writeVerboseLogMessages
                };

            var successful = command.Execute();

            if (false == successful)
                commandLog.Error("The SetVersionAttributesInFiles activity failed.");
        }