-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
csproj: Target/Exec regression in VS 2019 #4210
Comments
Cc: @jgoshi |
Thank you Brad. Adding @rainersigwald @livarcocc |
This appears to have been caused by #3584, because of an underlying difference in how |
Setting |
@rainersigwald is a possible fix to use explicit escaped carriage returns in the xml project files generated by CMake, i.e. |
@lukka That's a great workaround that appears to work fine in my simplified repro: <Project>
<Target
Name="test_cs_debug">
<!-- <Exec Command="echo Generating test.cs" /> -->
<Exec Command="setlocal
copy test.cs.in test.cs
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd" />
</Target>
</Project> But ideally we'd fix the MSBuild behavior change; it wasn't intentional. |
Introduce an end-to-end test using `loadProjectReadOnly` and a multiline `Exec` task.
Introduce an end-to-end test using `loadProjectReadOnly` and a multiline `Exec` task.
Another possible workaround here is to use a property instead of defining the script directly in the Command attribute: <Project>
<PropertyGroup>
<CommandToCreateFile>setlocal
copy test.cs.in test.cs
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</CommandToCreateFile>
</PropertyGroup>
<Target
Name="test_cs_debug">
<!-- <Exec Command="echo Generating test.cs" /> -->
<Exec Command="$(CommandToCreateFile)" />
</Target>
</Project> |
@krwq Is there anything else we can do than use XmlTextReader and lose the perf benefit of ignoring comments? |
I can't remember anything about this, but XmlTextReader, like many of the major Xml types, is rich with virtual methods. Is it possible to make a more efficient one (dumping comments) by selectively overriding bits? [edit] analogous to |
@danmosemsft I hope so, and plan to look into that . . . after 16.0. I'm worried about changing that sort of thing at this point in the release cycle. Reactivated #2576 and assigned it to 16.1. |
I'm going to merge this and prepare an insertion-to-VS PR. Don't let that stop anyone from describing a brilliant scoped fix that tweaks XmlReader behavior, should you come up with one! |
Works around a behavior difference between XmlReader and XmlTextReader that caused newlines in attributes to be ignored in command-line builds. Fixes dotnet#4210.
Support multi-line Exec Commands, fixing #4210.
Have you perhaps tried putting the script in the explicit CDATA i.e.:
(haven't tried but usually XML parsers treat it as a single blob and don't touch the content - this won't work directly in the attribute though) Generally XML spec allows XML parsers for quite a bit of freedom for handling white spaces and especially new lines (perhaps too much) - I think the only reasonable option to force any behavior to be exactly as desired is do what @danmosemsft has suggested above. Note wrapping XmlReader/Write is quite wide-spread in the XML implementation so I believe that is the right way to go. |
CDATA is a good idea but I don't think it helps here, since putting the command in a property and referencing the property already works around the attribute-newline difference. This fix was approved for 16.0 and has been checked into an internal VS branch. If you see something like it and your MSBuild version is higher than 16.0.452, please yell loudly. Thanks for reporting @bradking! |
Fixes #2576 ### Context The code already has support for parsing project files as read-only when we know that we're not going to be asked to write them back to disk. This flag is currently unused because the initial implementation in #3584 introduced a regression related to whitespace in attribute values (#4210). ### Changes Made Trivially reverted part of #4213 that addressed the regression and added a hack to make `XmlReader` behave the same as `XmlTextReader`. ### Testing Existing unit tests for correctness and ETW for performance. `XmlDocumentWithLocation.Load()` is ~26% faster with this change compared to baseline when building .NET Core projects. This translates to about 10 ms per one incremental CLI build of a Hello world application.
Steps to reproduce
Extract CSharpExec.zip.
At a VS 2019 RC x64 command prompt with the working directory set to the extracted folder:
>msbuild CSharpExec.csproj -p:Configuration=Debug -p:VisualStudioVersion=16.0
Observe the build failure.
Expected behavior
It is expected to build successfully, as it does at a VS 2017 x64 command prompt:
Actual behavior
The build fails at a VS 2019 RC x64 command prompt:
The text was updated successfully, but these errors were encountered: