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.

Ideas needed: Concise syntax for [System.IO.Path]::Combine()

See original GitHub issue

Combining paths is a common operation in a build system. Now that MSBuild is cross-platform, it’s even more fraught with danger due to the vagaries of slash directions.

Most MSBuild projects just use $(Path1)\$(Path2). This works and is concise but has some downsides:

  • Has an explicit slash direction
  • Can result in doubled slashes (if Path1 has a trailing slash)
  • Isn’t obviously a path-combining expression–it’s indistinguishable from string concatenation (because that’s what it is).

The most-obviously-correct approach is $([System.IO.Path]::Combine('$(Path1)', '$(Path2)')). That doesn’t have any of those downsides, but is verbose and hard to read (and type).

It would be great if we could have a concise syntax that called the cross-platform supported system API, but wasn’t unreadable. Ideas welcome!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:5
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
dasMullicommented, Feb 24, 2017

Is there any resolution for “extension methods” for properties? If so, one could make a method similar to how string instance methods can be used:

$(PublishDir.Sub('pkg').Sub('stage0'))
2reactions
eerhardtcommented, Feb 24, 2017

To make things more concise, is there a way you could you drop the $([MSBuild]::). part and if there is no prefix/class imply [MSBuild]?

Say: $(::NormalizeDirectory($(Path1), $(Path2))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Path.Combine Method (System.IO)
This method is intended to concatenate individual strings into a single string that represents a file path. However, if an argument other than...
Read more >
How do I use Join-Path to combine more than two strings ...
You can use the .NET Path class: [IO.Path]::Combine('C:\', 'Foo', 'Bar').
Read more >
System.IO.Path.Combine to merge File Path
Combine (sourcePath, fileName); string destFile = System.IO.Path.Combine(targetPath, fileName); // To copy a folder's contents to a new location:
Read more >
C# Tutorial - C# Path Combine(String, String)
Path Combine (String, String) Combines two strings into a path. Syntax. Path.Combine(String, String) has the following syntax. public static string Combine ...
Read more >
Apache Beam Programming Guide
Apache Beam is an open source, unified model and set of language-specific SDKs for defining and executing data processing workflows, and also data...
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