question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Indentation on .csproj breaks the build

See original GitHub issue

Indentation breaks the .csproj file.

Error:

dotnet build DoesntWorks.csproj
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 40.4 ms for /Users/dario/src/core-dal/src/CoreViejo/DoesntWorks.csproj.
/usr/local/share/dotnet/sdk/2.1.200/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.TargetFrameworkInference.targets(96,5): error : The TargetFramework value 'netcoreapp2.0' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly. [/Users/dario/src/core-dal/src/CoreViejo/DoesntWorks.csproj]

Build FAILED.

/usr/local/share/dotnet/sdk/2.1.200/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.TargetFrameworkInference.targets(96,5): error : The TargetFramework value 'netcoreapp2.0' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly. [/Users/dario/src/core-dal/src/CoreViejo/DoesntWorks.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.06

File that works:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>

Indented file that doesn’t works:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>
			netcoreapp2.0
		</TargetFramework>
	</PropertyGroup>
</Project>

Solution: Disabling indentation tool on Visual Studio Code for .csproj files.

My dotnet --info:

.NET Command Line Tools (2.1.200)

Product Information:
 Version:            2.1.200
 Commit SHA-1 hash:  2edba8d7f1

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.13-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.200/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.7
  Build    : 2d61d0b043915bc948ebf98836fefe9ba942be11

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
livarcocccommented, May 28, 2018

I don’t believe the problem here is the indentation but the newlines in the target framework value.

1reaction
BobFrankstoncommented, Oct 13, 2021

The proper title is

Whitespace is not being trimmed

This is far simpler than this discussion indicates. Normally leading and trailing whitespace is ignored in HTML and XML. Simply observing that convention solves the problem. The bug is not that the build fails, the bug is that whitespace is significant.

I was amused by http://usingxml.com/Basics/XmlSpace which complained that the default Microsoft parse trims whitespace.

There are no newlines, indentations, or whatever. There is just whitespace that is to be trimmed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio web csproj file indenting flipping between ...
The indentation of our web .csproj file is being changed to spaces or tabs, depending on the particular installation/user/machine doing the ...
Read more >
csproj files initially display wrong indent
Create a new .NET Core C# project called TestIndent. * Open the .csproj file by right clicking on the project in Solution Explorer...
Read more >
Copy with proper indentation - Visual Studio Blog
You want to share some code you've written with a colleague, so you select it in the editor and hit Ctrl + C...
Read more >
Solution files are a nightmare that has to disappear and ...
Solution files provide accurate control over projects, build configs, ... Impossible to edit large files because it's indentation sensitive.
Read more >
What setting in visual studio forces indentation on new line ...
What I would like is for a new line to come down to the same indentation, so that I can place my curly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found