Skip to content

Commit

Permalink
Ensure to unescape special MSBuild characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjvh80 committed Nov 27, 2014
1 parent 28460d9 commit bc51566
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/app/FakeLib/MSBuildHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ let xname name = XName.Get(name, msbuildNamespace)
let loadProject (projectFileName : string) : MSBuildProject =
MSBuildProject.Load(projectFileName, LoadOptions.PreserveWhitespace)

// See: http://msdn.microsoft.com/en-us/library/ms228186.aspx
let internal unescapeMSBuildSpecialChars s =
let replExpr = new Text.RegularExpressions.Regex("%..")
replExpr.Replace(s, new Text.RegularExpressions.MatchEvaluator(
fun _match -> match _match.Value with
| "%24" -> "$" | "%25" -> "%" | "%27" -> "'" | "%40" -> "@"
| "%3B" -> ";" | "%3F" -> "?" | "%2A" -> "*"
| _ -> _match.Value))

/// [omit]
let internal getReferenceElements elementName projectFileName (doc : XDocument) =
let fi = fileInfo projectFileName
doc.Descendants(xname "Project").Descendants(xname "ItemGroup").Descendants(xname elementName)
|> Seq.map (fun e ->
let a = e.Attribute(XName.Get "Include")
let value = convertWindowsToCurrentPath a.Value
let value = a.Value |> unescapeMSBuildSpecialChars |> convertWindowsToCurrentPath

let fileName =
if value.StartsWith(".." + directorySeparator) || (not <| value.Contains directorySeparator) then
Expand Down

0 comments on commit bc51566

Please sign in to comment.