[build] Passing a property (/property) with multiple values to msbuild isn't working
See original GitHub issueI need to pass values for NoWarn
option to C# compiler. Previously with msbuild it was being passed as property:
msbuild /p:NoWarn:"1591;1573;3001;3002"
But with dotnet cli it doesn’t work anymore.
I tried both build
and msbuild
commands.
Steps to reproduce
dotnet.exe msbuild /property:NoWarn=1591;1573;3001;3002 mysolution.sln
or
dotnet.exe msbuild /property:NoWarn="1591;1573;3001;3002" mysolution.sln
or
dotnet.exe msbuild "/property:NoWarn=1591;1573;3001;3002" mysolution.sln
all result in
MSBUILD : error MSB1006: Property is not valid.
Switch: 1573
With dotnet.exe
build` there’s the same error.
While if I set these values in csproj:
<NoWarn>1591;1573;3001;3002</NoWarn>
it works as expected (warning are being ignored)
Expected behavior
Pass all warning code to the compiler.
Actual behavior
Faulting with an error
Environment data
dotnet --info
output:
D:\>dotnet --info
.NET Command Line Tools (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9
Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.0\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
[build] Passing a property (/property) with multiple values to ...
I need to pass values for NoWarn option to C# compiler. Previously with msbuild it was being passed as property: msbuild /p:NoWarn:"1591 ...
Read more >Passing multiple values to Wix DefineConstants property ...
The problem: The MSBuild task (not MSBuild.exe, the MSBuild task named MSBuild) cannot handle multiple constants used by WIX projects.
Read more >Comparing Properties and Items - MSBuild
Learn how MSBuild properties and items pass information to tasks, evaluate conditions, and store values that the project file can reference.
Read more >MSBuild Properties
Learn how MSBuild name-value property pairs can pass values to tasks, evaluate conditions, and store values.
Read more >Msbuild get directory name. props imported, or something ...
Passing input parameters as properties. There are many variations of using msbuild this way. Some are assigned by MSBuild to items when items...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@evil-shrike unfortunately the fix I made regressed the ability to define multiple properties with a single property option, e.g.
/property:First=foo;Second=bar
. See https://github.com/dotnet/cli/issues/9369.After discussion with the MSBuild team, we’ve decided to revert the fix and request that users pass literal quotes on the command line around the property’s value to get the desired behavior. See this comment here for the decision that was previously made for MSBuild on .NET Core.
So to do what you want, you’ll need to pass literal double quotes through to MSBuild. On most macOS/Linux shells, this can be accomplished by using single quotes surrounding the double quoted value:
The single quotes will treat both the double quotes and semicolons as literal values, so no need to escape either.
On Windows, you’ll need to use escaped double quotes:
Thanks!
The fix is now in the
release/2.1.4xx
branch, which is slated to ship sometime after 2.1 is released (sorry, we’re too close to shipping 2.1 to take a fix in that release).Thanks again for reporting this issue to us!