DRYing <TargetFramework> sometimes works, sometimes breaks

Viewed 311

As I write this, we have 2,497 .csproj files in our entire organization.

We have one policy, and that is "mono-everything". It means that for the sake of reducing costs, and increasing quality, we upgrade the whole organization. Everything should be upgraded when we decide to upgrade anything.

Now, after upgrading to .NET Core 3.0 which was and is a painful process, we decided to DRY <TargetFramework> and remove Debug\netcoreapp3.0 from output folder. We want this policy to be applied to ALL of our projects. So we came up with this ProjectDotNetCore.targets file:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <OutputPath>.\bin</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
  </PropertyGroup>

</Project>

And we use this .targets file in all of those 2500 .csproj files. This way, we can assure a single behavior across the entire organization. So a typical .csproj file would look like this:

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

  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>

  <PropertyGroup>
    <AssemblyName>HolismCommerce.Sammerce.AdminService</AssemblyName>
    <RootNamespace>HolismCommerce.Sammerce.AdminService</RootNamespace>
  </PropertyGroup>

  <Import Project="$(OrganizationProjectsRoot)\Framework\ProjectDotNetCore.targets" />

</Project>

The problem is that, sometimes it works, sometimes it doesn't work and we receive this error:

Error NETSDK1013 The TargetFramework value 'netcoreapp3.0' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.

Why it has non-deterministic behavior? We want to be able to set <TargetFramework> of all projects from a central location. How can we debug it?

0 Answers
Related