Search code examples
c#.netmsbuilddotnet-build

SDK exe project creates net472 folder when build


I've made major changes in the solution, mainly converting projects into SDK style projects. The solution contains projects with various FW (.net4.0, .net 4.6.1, .net4.7.2, .net4.8). My startup project is a .net FW 4.7.2 console application (*.exe) also converted into SDK project style. When I build the solution\startup project, the exe file is located in a newly created folder in the output directory - named net472 (bin\debug\net472). The net472 contains the exe file along with other dlls, while there are dlls also in the "original" output directory (bin\debug)

There isn't any special property in the csproj - I edited it to include output directory, but it didn't affect. What could be the reason for that and what should I do, to locate the exe together with the rest of the DLLs, in the "original" output directory?


Solution

  • SDK projects will automatically append the target framework moniker (TFM) (e.g. net472 or net8.0) and, if present, the runtime identifier (RID) (e.g. win-x64 or osx-arm64). An example output path is bin\Debug\net5.0\win-x64.

    The AppendTargetFrameworkToOutputPath and AppendRuntimeIdentifierToOutputPath properties can be set to false to disable the automatic behavior and ensure an output path of bin\Debug.

      <PropertyGroup>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
      </PropertyGroup>
    

    To apply these property settings to all your projects, add the properties in a Directory.Build.targets file that applies to all your projects.