본문 바로가기

C# .Net

[.net] .net Standard에서 Linq to sql 파일 생성하기

참고원문 https://weblog.west-wind.com/posts/2017/Jun/22/MultiTargeting-and-Porting-a-NET-Library-to-NET-Core-20


.Net Standard로 프로젝트를 생성하면 .Net Core와 .Net Framework에서 사용될 수 있는 특성들을 함께 적용할 수 있다.


닷넷 스탠다드 프로젝트를 생성하면 Linq to Sql class가 추가가 안되는데, 이 때 타겟 프레임워크를 csproj의 targetframework 태그를 수정하면 된다.

(properties에서 표시되는 ui로는 .net framwork로 타겟 프레임워크를 변경할 수 없다.)


<TargetFrameworks>net45;net40;netstandard2.0</TargetFrameworks>


복수의 타깃을 지정하고 싶으면 세미콜론으로 구분하면 된다.

타깃별 설정을 지정하고 싶다면 조건식을 사용할수도 있다.

위의 링크에서 가져온 개략적인 사용법을 담은 전체 설정파일


<!-- common NuGet package refs that affect all projects -->
<ItemGroup>
	<TargetFrameworks>net45;net40;netstandard2.0</TargetFrameworks>
	<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
</ItemGroup>


<!-- .NET Standard 2.0 references, compilation flags and build options -->
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
	<DefineConstants>NETCORE;NETSTANDARD;NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
	<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
</ItemGroup>


<!-- .NET 4.5 references, compilation flags and build options -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">		
	<Reference Include="mscorlib" />
	<Reference Include="System" />
	<Reference Include="System.Core" />
	<Reference Include="Microsoft.CSharp" />		
	<Reference Include="System.Data" />
	<Reference Include="System.Web" />
	<Reference Include="System.Drawing" />
	<Reference Include="System.Security" />
	<Reference Include="System.Xml" />
	<Reference Include="System.Configuration" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45'">
	<DefineConstants>NET45;NETFULL</DefineConstants>
</PropertyGroup>