Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet new removes PropertyGroup related to build inside csproj #1195

Closed
marcusien opened this issue Aug 9, 2017 · 4 comments
Closed

dotnet new removes PropertyGroup related to build inside csproj #1195

marcusien opened this issue Aug 9, 2017 · 4 comments

Comments

@marcusien
Copy link

Hi,

Is it posible for the "dotnet new" command not to remove the s from csproj which are related to build stuffs.
For instance, I got this in a "net core" csproj :
<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'"

@seancpeters
Copy link
Contributor

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.

@marcusien
Copy link
Author

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 ?

@seancpeters
Copy link
Contributor

It's fixed in the current newest bits available at http://gitHub.com/dotnet/cli/ - for example 2.0.1-servicing-006924

@marcusien
Copy link
Author

Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants