Search code examples
.net-corecsproj

Debug specific PropertyGroup in csproj file


Is it possible to have a section of my csproj file in dotnet core (3.1.1) which is only included when debugging? I'd like to accomplish something like the following

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>  <!--always valid-->
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
    <AssemblyName>SomeAssembly</AssemblyName>
    <RootNamespace>Some.Root.Namespace</RootNamespace>
</PropertyGroup>
<PropertyGroup> <!--Debugonly-->        
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

....
</Project>

Solution

  • Yes, use conditional PropertyGroup:

    <PropertyGroup Condition="'$(Configuration)'=='Debug'">
        <!--Debugonly-->
    </PropertyGroup>