0

I've got an old-style Settings class in my project, but I'm trying to convert to netstandard2.0 and I'd like to drop that option while being backwards-compatible and including it on net45 builds.

I've figured out how to exclude the constructor where I'm using it, but I also have to remove it from the build using the .csproj.

My .cs:

public class Client
{
    #if !NETSTANDARD2_0
    public Client(Settings settings) { this.url = settings.Url }
    #endif
}

My .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Properties\Settings.Designer.cs" Condition="" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
  </ItemGroup>

</Project>
Kyle Sletten
  • 5,137
  • 2
  • 25
  • 38
  • 1
    https://stackoverflow.com/questions/43173811/how-do-i-exclude-files-folders-from-a-net-core-standard-project Use the new syntax to exclude that file, and add a condition to test `Condition="'$(TargetFramework)'!='net45'"` – Lex Li Sep 01 '18 at 03:22

1 Answers1

1

You can exclude them via a pattern:

<Compile Remove="**\*.Designer.cs" Condition="'$(TargetFramework)' == 'net45'" />
Martin Ullrich
  • 78,211
  • 20
  • 211
  • 189