dotnet / upgrade-assistant

A tool to assist developers in upgrading .NET Framework applications to .NET 6 and beyond
MIT License
1.11k stars 163 forks source link

Upgrade Assistant moves closing Tag of empty Tag-Pair to new line #1299

Open sigma-schn opened 2 years ago

sigma-schn commented 2 years ago

Describe the bug

After the Upgrade of a net48 WPF project to a net6 WPF project, the closing Tags of empty Tag-Pairs that were in the original csproj-file are moved to a new line. This leads to a not-loadable csproj-file, if the OutputPath-Tag was modified. Example: Prior to upgrade:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath></OutputPath>
  </PropertyGroup>

After Upgrade:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>
    </OutputPath>
  </PropertyGroup>

This produces the error: [MSB4184] Der Ausdruck "[System.IO.Path]::Combine(******, \)" kann nicht ausgewertet werden. Illegales Zeichen im Pfad. C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets at (322:5)

(Path obfuscated)

To Reproduce

Exceptions (if any)

Further technical details

brandonh-msft commented 2 years ago

@sigma-schn this seems to be table-stakes for an XML parser & writer so I am surprised it is the cause of your failure. Can you provide a csproj (before conversion) which causes this behavior, by chance? We have migrated many csproj files and not seeing this cause a problem.

I wonder if the root of the issue is that OutputPath is present in the file yet being unused. If you remove it from the source file, what happens? Or is there a particular reason you need it present but empty?

c2dev commented 1 year ago

@brandonh-msft I can confirm that the error is caused by the OutputPath element in the csproj file being separated onto multiple lines. If you remove the line break the csproj file will load just fine in Visual Studio.

This was our project file before running the upgrade assistant:

<PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <OutputPath></OutputPath>
</PropertyGroup>

After running the upgrade assistant, our project file looked like this:

<PropertyGroup>
    <TargetFramework>netstandard20</TargetFramework>
    <OutputPath>
    </OutputPath>
</PropertyGroup>

In order to load the project in Visual Studio, I had to remove the line break. I whole heartedly agree, OutputPath doesn't need to be there since it is blank, but a lot of us have solutions with hundreds of projects that have this in there as empty by default.

Anyway, just confirmation that @sigma-schn is correct in his analysis of the issue.