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

MSBuild properties are incorrectly formatted #4297

Open
2 tasks done
Lordfirespeed opened this issue Mar 10, 2024 · 2 comments
Open
2 tasks done

MSBuild properties are incorrectly formatted #4297

Lordfirespeed opened this issue Mar 10, 2024 · 2 comments

Comments

@Lordfirespeed
Copy link

Lordfirespeed commented Mar 10, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

Cake runner

Cake Frosting

Cake version

4.0.0

Operating system

Linux

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

MSBuild arguments are rendered like so:

/property:DefineConstants=foo;bar;baz

Which leads to an error:
image

What is expected?

MSBuild properties should be specified in the correct format. For example:

/property:DefineConstants=foo;DefineConstants=bar;DefineConstants=baz

Steps to Reproduce

Create a task with the following Run implementation:

var buildSettings = new DotNetBuildSettings {
    Configuration = "Release",

    MSBuildSettings = new() {
        Properties = {
            {"DefineConstants", ["foo", "bar", "baz"] },
        },
    },
};

context.DotNetBuild(context.RootDirectory, buildSettings);

Ensure that context.RootDirectory is defined.

Run the task.

Notes

Related: #1852
Of note, I believe this comment is incorrect.
Perhaps WithProperty("DefineConstants", "A=a", "B=b"); should instead generate:

/p:DefineConstants=A=a;DefineConstants=B=b
@Lordfirespeed Lordfirespeed changed the title Bash interprets semicolon-delimited property values for MSBuild incorrectly MSBuild properties are incorrectly formatted Mar 10, 2024
@Lordfirespeed
Copy link
Author

Leaving this here for any future unfortunate souls -
When working with DefineConstants, semicolons within its property value need to be escaped with %3B.

The solution I proposed above will not work, each subsequence DefineConstants overwrites the value of the previous. The rendered constants ["foo", "bar", "baz'] should loook like:

/p:DefineConstants=foo%3Bbar%3Bbaz

@Lordfirespeed
Copy link
Author

Lordfirespeed commented Mar 10, 2024

This does beg the question: Why are semicolons explicitly not escaped for DefineConstants?

private static readonly HashSet<string> _propertiesNotEscapeSemicolons = new HashSet<string>
{
    "DefineConstants",
    "ExcludeFilesFromDeployment"
};

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

1 participant