.NET Framework 4.8 및 4.8.1 역시 SDK Style 프로젝트의 지원 대상에 포함되기 때문에, 자연스럽게 File-based App에서도 지원 대상에 해당됩니다.
예를 들어, 전형적인 .NET Framework 애플리케이션 개발에 쓰이는 요소를 모두 포함한다면 아래와 같이 작성할 수 있겠습니다.
#:property TargetFramework=net48
#:property PublishAot=False
#:property Nullable=Disable
#:property ImplicitUsings=Disable
#:property LangVersion=7.3
#:package log4net@3.2.0
// Run with: dotnet run --no-cache Program.cs
using System;
using System.Configuration;
using System.Xml.Linq;
using log4net;
using log4net.Config;
internal static class Program
{
private static ILog log = LogManager.GetLogger(typeof(Program));
[STAThread]
private static void Main(string[] args)
{
XmlConfigurator.Configure();
log.Debug("Main() started");
try
{
var targetUrl = ConfigurationManager.AppSettings["TargetUrl"];
log.InfoFormat("Target URL: {0}", targetUrl);
var doc = XDocument.Load(targetUrl);
log.Info(doc.ToString());
}
catch (Exception ex)
{
log.Error("Cannot load XML document.", ex);
}
}
}
여기서는 log4net NuGet 패키지를 사용하며, ConfigurationManager를 사용하는 예시를 들고 있어서, 아래와 같이 app.config
파일도 디렉터리에 같이 넣었습니다.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date : %message %newline"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="ConsoleLog"/>
</root>
</log4net>
<appSettings>
<add key="TargetUrl" value="https://www.nuget.org/api/v2/"/>
</appSettings>
</configuration>
마지막으로, SDK 스타일 프로젝트는 기본적으로 일일이 모든 파일에 대한 레퍼런스 참조를 하지 않아도 되기 때문에, nuget 패키지가 아닌 .NET Framework 어셈블리 참조 지정을 위해 Directory.Build.props
파일을 추가로 같은 디렉터리에 넣어둡니다.
<Project>
<ItemGroup>
<!-- Add .NET Framework references here (For NuGet packages, use the #:package directive instead.)-->
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>
이렇게 프로젝트를 setup한 다음, VS Code로 편집 경험이 잘 작동하는지 살펴보면 당연하게도 잘 작동합니다.
실행을 할 때에는 dotnet run Program.cs
로 실행해도 되지만, .NET Framework 애플리케이션 빌드 환경은 아쉽게도 .NET 10의 FBA 캐싱과는 맞지 않는 부분이 있습니다. (Cache Invalidation이 일어나야 하는 부분이 C# 파일 외에도 app.config이나 다른 파일에도 트리거 포인트가 있어야 합니다.)
그래서, 명확한 확인을 위하여 아래처럼 실행하는 편이 정확합니다.
dotnet run --no-cache Program.cs
이처럼 File-based App으로 .NET Framework 코드를 옮길 수 있으므로, 자연스럽게 .NET Framework 기반 애플리케이션이라고 할지라도 바이브코딩의 이점을 그대로 누릴 수 있다고 말할 수 있습니다.