첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;
using System.IO;
using System.Text;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            string sourceDirectoryPath = @"D:\DEVELOPMENT\ARCA\ARCA";
            string sourceVersion       = "4.5.2";
            string targetVersion       = "4.7.2";

            Console.WriteLine($"SOURCE DIRECTORY PATH : {sourceDirectoryPath}");

            if(!Directory.Exists(sourceDirectoryPath))
            {
                Console.WriteLine("NO SOURCE DIRECTORY FOUND");

                return;
            }

            UTF8Encoding encoding = new UTF8Encoding(true);

            string[] projectFilePathArray = Directory.GetFiles(sourceDirectoryPath, "*.csproj", SearchOption.AllDirectories);

            if(projectFilePathArray.Length == 0)
            {
                Console.WriteLine("NO PROJECT FILE FOUND");
            }
            else
            {
                Console.WriteLine($"PROJECT FILE FOUND : {projectFilePathArray.Length}");
            }

            foreach(string projectFilePath in projectFilePathArray)
            {
                try
                {
                    string content = File.ReadAllText(projectFilePath, encoding);

                    content = content.Replace
                    (
                        $"<TargetFrameworkVersion>v{sourceVersion}</TargetFrameworkVersion>",
                        $"<TargetFrameworkVersion>v{targetVersion}</TargetFrameworkVersion>"
                    );

                    File.WriteAllText(projectFilePath, content, encoding);
                }
                catch(Exception exception)
                {
                    Console.WriteLine($"ERROR UPDATE PROJECT FILE : {Path.GetFileName(projectFilePath)}");
                    Console.WriteLine($"    EXCEPTION : {exception}");
                }
            }

            string[] appConfigFilePathArray = Directory.GetFiles(sourceDirectoryPath, "App.config", SearchOption.AllDirectories);

            if(appConfigFilePathArray.Length == 0)
            {
                Console.WriteLine("NO APP.CONFIG FILE FOUND");
            }
            else
            {
                Console.WriteLine($"APP.CONFIG FILE FOUND : {appConfigFilePathArray.Length}");
            }

            foreach(string appConfigFilePath in appConfigFilePathArray)
            {
                try
                {
                    string content = File.ReadAllText(appConfigFilePath, encoding);

                    content = content.Replace
                    (
                        $@"<supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v{sourceVersion}""/>",
                        $@"<supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v{sourceVersion}"" />"
                    );

                    content = content.Replace
                    (
                        $@"<supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v{sourceVersion}"" />",
                        $@"<supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v{targetVersion}"" />"
                    );

                    File.WriteAllText(appConfigFilePath, content, encoding);
                }
                catch(Exception exception)
                {
                    Console.WriteLine($"ERROR UPDATE APP.CONFIG FILE : {Path.GetFileName(appConfigFilePath)}");
                    Console.WriteLine($"    EXCEPTION : {exception}");
                }
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요