■ 닷넷 프레임워크 소스 코드에서 닷넷 프레임워크 버전을 일괄 변경하는 방법을 보여준다.
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
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 } } |