19

I have a command line like this in my post-build event:

aspnet_regiis -pef connectionStrings "$(ProjectDir)" -prov "DataProtectionConfigurationProvider"

But aspnet_regiis is returning a failure because the tralling \ in the directory. Pass full name, path + web.config doesn't work either.

How can I solve this?

Jack
  • 16,276
  • 55
  • 159
  • 284
  • 3
    A workaround I often use in these situations is appending a `.` to the end of the path. – Cameron May 02 '16 at 05:17
  • Visual auto defined paths have usually a trailing backslash. This is windows usage (even if we all know it's a bad habit, and want to fix it... but when in Rome...) – Sandburg Feb 03 '23 at 16:08

1 Answers1

50

You can use the TrimEnd function to trim the trailing slash character

$(ProjectDir.TrimEnd('\'))

I found this option in this post

Community
  • 1
  • 1
Thangadurai
  • 2,573
  • 26
  • 32
  • thanks, I was looking if VS's variables had support to functions, like in your example – Jack May 02 '16 at 05:41
  • 4
    if anyone want to know more about this property functions: https://msdn.microsoft.com/en-us/library/dd633440.aspx – Jack May 02 '16 at 15:46
  • 1
    Ha, as if that works! Also thanks to @jack for the further references – Andrew Bullock May 02 '20 at 14:03
  • 1
    Anyone got an idea how this can be achieved in the Core toolchain? This seems to be MSBuild only and in my dotnet (Core 3.1) project it just returns an empty string... – SharpShade Aug 12 '20 at 09:41