MSBuild property expansion creates a new line in the Exec command - msbuild

I am having some problems running a powershell script in a targets file that is being included into some projects.
The MSBuild version is
16.11.0.36601
The following is the relevant stuff from the target file:
<PropertyGroup>
<ScriptLocation>
'$(SolutionDir)subdir\script.ps1'
</ScriptLocation>
...
</PropertyGroup>
<Exec Command="powershell -noprofile -NonInteractive -executionpolicy Unrestricted -File $(ScriptLocation)" />
My problem occurs when the property is expanded. For some reason it appears on a new line, this makes the command fail.
This is the Output:
0>powershell -noprofile -NonInteractive -executionpolicy Unrestricted -File
'C:\code\app\subdir\script.ps1'
0>The command cannot be run because the File parameter requires a file path. Supply a path for the File parameter and then try the command again.
and then script.ps1 is opened in my default editor.
So essentially it's running powershell -noprofile -NonInteractive -executionpolicy Unrestricted -File and then continuing and trying to run the next line, i.e. 'C:\code\app\subdir\script.ps1'
I can't make this work at all - even when I replace it with the documented method here: https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/advanced-enterprise-web-deployment/running-windows-powershell-scripts-from-msbuild-project-files#executing-a-windows-powershell-script-on-the-build-server
When I do that - the following happens:
0>powershell -noprofile -NonInteractive -executionpolicy Unrestricted -Command "&{ &'
C:\code\app\subdir\script.ps1
' } "
0>The string is missing the terminator: '.
0> + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
0> + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
0>
0>''' is not recognized as an internal or external command
...
Is there a way to tell MSBuild NOT to expand the property on a new line? If not, Is there a way I can wrap things so this doesn't happen?
Rewriting the script in batch or equivalent is not really an option.

When defining a property, it includes any line breaks into that property.
This:
<ScriptLocation>
'$(SolutionDir)subdir\script.ps1'
</ScriptLocation>
is not the same as this:
<ScriptLocation>'$(SolutionDir)subdir\script.ps1'</ScriptLocation>

Related

I can not create a react-native project?

PS D:\reactnative> expo init Mobileapp
expo : File C:\Users\admin\AppData\Roaming\npm\expo.ps1 cannot be loaded because running scripts is disabled on this system. For more information,
see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
expo init Mobileapp
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
It sounds like you haven't given powershell the proper privileges to execute the expo powershell script. To verify, run Get-ExecutionPolicy in powershell. If it prints Restricted, then you haven't enable powershell to run scripts, which is why you are getting that error.
I'm not sure of what's the proper execution policy to have, but base on the link your error provided, then RemoteSigned is the one you want. Open powershell as an administrator and set it with
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

how to run compound script statements from cmake?

I have a complex/compound command that I want to execute as patch command during execution of my ExternProject_Add using this macro
macro(SET_PATCH_CMD arg)
message(STATUS "Patch command : ${arg};${ARGN}")
set(${PROJECT_NAME}_patch_cmd ${arg};${ARGN})
endmacro(SET_PATCH_CMD)
I dont remeber or am not sure why I added a ; between ${arg} and ${ARGN}, but patch commands like
mkdir -p <SOURCE_DIR>/install
are working as expected in my cmake project.
When I set a simple command like
SET(PATCH_CMD <SOURCE_DIR>/scripts/my_schript.sh)
patch command executes as expected, but the moment I start adding arguments to script with spaces in between
SET(PATCH_CMD <SOURCE_DIR>/scripts/my_schript.sh arg1 arg2 arg3)
SET_PATCH_CMD(${PATCH_CMD})
I get Command failed: No such file or directory
clearly spaces in my command are messing up the way cmake runs the shell script/command. Any help on making it work is appreciated.

when i type command at windows terminal http-server

when i type command at windows terminal http-server following error occured
error
http-server
http-server : File C:\Users\RKanth\AppData\Roaming\npm\http-server.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ http-server
+ ~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Open PowerShell by Run as Administrator
Run the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Confirm with ‘Y’
Open PowerShell by Running as Administrator using the windows search bar.
Run the following command: Get-ExecutionPolicy
Then you can See: Restricted
Again run the following command: Set-ExecutionPolicy Unrestrict
Press y
Now you can Run again the following command and check: Get-ExecutionPolicy
Then you can See: Unrestricted
Done!!!

How to use command prompt via vb.net to use BCDEDIT

I have a batch file which contains some commands with bcdedit.
but in my vb.net application when I run that batch file via: Process.Start("CMD", " /C \blahblah\test.bat") it says bcdedit is not recognized.
so what I've found so far is the cmd.exe that vb.net opens it doesn't recognize bcdedit command at all.

Powershell not exiting

cd "C:\apache-tomcat-7.0.67\bin"
.\shutdown.bat
.\startup.bat
I have above command in powershell file, but problem is that, powershell has not exited after .\startup.bat.
So, for solving this issue i have used following command, but then apache is not working for me
START "C:\apache-tomcat-7.0.67\bin\startup.bat"
If startup.bat does not exit, start it with Start-Process without the -wait parameter.
Start-Process .\startup.bat
(use the relative path in the working directory, not a global path)