1

I'm working on a project with an external API that requires me to manually compile an assembly through PowerShell. I have to manually include each of the API's references as compile options, which could end up being 5 or 6 different references. So I'd like to be able to write all of these compile options on multiple lines for readability, and thought encapsulating these instructions inside a PowerShell script would be viable.

However, PowerShell sees newlines as a separate command, so having

csc /target:library
/reference:xx\xx\xx\xx.dll

Doesn't work. It thinks /reference is supposed to be a cmdlet.

Is this kind of functionality even possible? Any help or advice would be greatly appreciated.

jhkmw3
  • 117
  • 1
  • 8
  • I don't think you can - I believe even [response file](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/response-file-compiler-option) expects all options on one line... – Alexei Levenkov Jun 24 '19 at 20:09

1 Answers1

0

The backtick (`) is the line continuation character in Powershell. This should work:

csc /target:library `
    /reference:xx\xx\xx\xx.dll

It's recommended to use a space before the backtick for reliable parsing.

Rich Moss
  • 2,195
  • 1
  • 13
  • 18
  • 1
    Thank you, I had tried this earlier but I think I had a space or something following a back tick which ended up breaking the code. Are there any other suggestions for improving readability? – jhkmw3 Jun 24 '19 at 20:21
  • That's correct - the backtick is Powershell's escape character and it's escaping the cr/lf so it has to be the last character on the line. For readability, you may have noticed that I indented the subsequent line to indicate it's part of the previous line. – Rich Moss Jun 24 '19 at 21:22