dotnet new removes PropertyGroup related to build inside csproj
Hi,
Is it posible for the "dotnet new" command not to remove the
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MyConfiguration|AnyCPU'">
<Optimize>False</Optimize>
</PropertyGroup>
But when I use my template to create a new project, this kind of PropertyGroup is simply removed.
This is more annoying for classic csproj that are contained in my templates, cause it removes this kind of propertygroup content (that are mandatory on classic csproj)
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
When I'm first trying to build my brand new project (created with my template), it does not build cause it tells me that "The OutputPath property is not set for project 'MyProject.csproj'"
HI @marcusien - there is a bug in some older versions (including 1.0.4) of dotnet new which causes some conditions in proj files to be incorrectly consumed during template creation. To work around this, there is a directive you can add to your proj file to turn off template engine processing. Specifically, add this to your csproj file before the PropertyGroup being incorrectly removed:
<!--/-:cnd:noEmit -->
This indicates that content following it should be emitted as-is, with no template processing occurring.
If there is content later in the file that should be processed, the processing can be turned back on using the slightly different directive:
<!--/+:cnd:noEmit -->
The csproj file in the template would end up looking something like this (extra comments added for clarity):
<Project>
<!-- This part needs to be processed by templating, which is the default, so no extra markup needed -->
<PropertyGroup>
...
</PropertyGroup>
<!-- This part should be written verbatim, turn off template processing -->
<!--/-:cnd:noEmit -->
<PropertyGroup>
...
</PropertyGroup>
...
<!-- More content which needs template processing, turn it back on -->
<!--/+:cnd:noEmit -->
...
</Project>
If there is no content needing processing after you've turned processing off, there's no need to turn it back on. The processing on/off is scoped to the file, so this wouldn't affect how other files in the template are handled.
Hi @seancpeters ,
I tried with your workaround and it works fine :) thank you !!
However I'm using the CLI version : v2.0.0-preview2-006497. It's not quite old. Any clue about the version that corrects this bug ?
It's fixed in the current newest bits available at http://gitHub.com/dotnet/cli/ - for example 2.0.1-servicing-006924
Thank you :+1: