Reputation: 4071
Under the project.json project system I was able to specify framework assembly dependencies per framework. The dotnet docs (now out of date) show the below example.
{
"frameworks":{
"net20":{
"frameworkAssemblies":{
"System.Net":""
}
},
"net35":{
"frameworkAssemblies":{
"System.Net":""
}
},
"net40":{
"frameworkAssemblies":{
"System.Net":""
}
},
"net45":{
"frameworkAssemblies":{
"System.Net.Http":"",
"System.Threading.Tasks":""
}
},
".NETPortable,Version=v4.5,Profile=Profile259": {
"buildOptions": {
"define": [ "PORTABLE" ]
},
"frameworkAssemblies":{
"mscorlib":"",
"System":"",
"System.Core":"",
"System.Net.Http":""
}
},
"netstandard16":{
"dependencies":{
"NETStandard.Library":"1.6.0",
"System.Net.Http":"4.0.1",
"System.Threading.Tasks":"4.0.11"
}
},
}
}
How do I do this under csproj for the updated dotnet sdk v1.1.1? I want to reference System.Configuration for net40, but not for netstandard 1.6.
Upvotes: 1
Views: 1537
Reputation: 4071
Thanks Pankaj - I went with a modified version of your suggestion. The key is just using the Reference element.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.6;net40</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.0" />
<PackageReference Include="Common.Logging" Version="3.4.0-Beta2" />
<PackageReference Include="NLog" Version="5.0.0-beta06" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<PackageReference Include="Common.Logging" Version="3.3.0" />
<PackageReference Include="NLog" Version="4.1.1" />
<PackageReference Include="Common.Logging.NLog40" Version="3.3.0" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Folder Include="Console\" />
</ItemGroup>
</Project>
Upvotes: 5
Reputation: 7802
You may follow below mentioned steps:
Change "TargetFramework" value to required .Net Framework version. e.g. Following example sets target framework version to 4.5.2
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
</PropertyGroup>
Reload project.
Add reference of System.Configuration assembly.
Unload and edit project again.
Edit System.Configuration reference as follows.
<ItemGroup>
<Reference Include="System.Configuration" Condition="'$(TargetFramework)'=='net452'" />
</ItemGroup>
There may be easy way out which I am not aware of but above method should work.
Upvotes: 1