MSDeploy Auto Generated deploy.cmd path issue? - batch-file

I've been working on trying to figure out why our auto-generated deploy.cmdscripts will not work when installed to C:\Program Files (x86)\OurProgram. I finally narrowed down the issue to the closing parenthesis in (x86) as the script would terminate with "Files was unexpected at this time". One possible solution was to manually create another batch file to set _DeploySetParametersFile to a Windows path ( C:\Program^ Files^ (x86^)\OurProgram\Program.Parameters.xml). This isn't a valid solution for me, so I dug into the auto generated file and found the issue to be 2 variables:
RootPath
_DeploySetParametersFile
Both of which were referenced using %'s(i.e. %RootPath%), however as soon as they were changed to !'s(i.e. !RootPath!), no 2nd script was needed and I can run the cmd script from Program Files (x86) just fine. The issue of course with this is, the deploy.cmd file is auto-generated on each build, thus I have to change it for each build I do. My question is this: Is there a way to edit the template Visual Studio uses to generate the deploy.cmd file? If so, where? It seems so ridiculous that Microsoft would have this be an issue in their web deployment.

Related

Post-Build Event Fails to Run Batch File

I recently started adding Post-Build events to my projects and today I came across an annoying issue.
Post-build event command line:
"$(ProjectDir)PostBuildRelease.bat"
PostBuildRelease.bat - 1
CMD
SET parameter=%1
CD %1
The above errors with message:
'´╗┐CMD' is not recognized as an internal or external command,
operable program or batch file.
"Saved parameter "
Which is strange, because I definitely have another project where the first line reads CMD and it works perfectly.
Setting the first line to SET parameter=%1 also complains that SET is not a recognised command.
PostBuildRelease.bat - 2
Trying the same but with an empty file gives this error (build fails):
The command "C:\Users\name\ITSelfHelp\ITHelp\PostBuildRelease.bat" exited with code 1.
PostBuildRelease - 3
Entering the CMD code directly into the Post-Build Event command line field results in a successful post-build event, but this is not ideal for me and seems strange as I can run from an external .bat in other projects.
Can anyone explain this behaviour, or let me know how I can debug this?
It turns out the text editor in Visual Studio was encoding my batch script.
To recreate this:
Right-click the solution
Add file
Text file
Rename file.bat
Write the script in Visual Studio
Build
Check the output window for the error
To resolve:
Delete the file created in Visual Studio
Created a new .bat file in the same location using Windows Explorer
Open the file with Notepad++ and paste in the script
Save and build
I also noticed that syntax highlighting was not being applying in the file created by Visual Studio, which is a bit of a giveaway along with the ´╗┐ in front of the errors.

Unable to do a simple rename file in ReleaseManagement during deployment

I have a problem that has been bugging me.
I have a Visual studio 2013 solution that goes through Release management.
One of the release steps in Release management is running a simple batch file using the Actions -> SxSBatchCommand tool. This is a custom action that simply executes a batch file and the batch file executes a simple rename that goes like this:
rename "$(currentDir)\project.ev1.app.config" "project.exe.config"
Which basically takes a specific app.config and applies it in the deployed directory as the main config.
All this works well but because I don't like all the batch files in my project, I decided to delete them and to use the WindowsOS -> Rename File or folder tool
So I deleted the SxSBatchCommand and added the "Rename File or Folder" with parameters:
FileFolderName: project.ev1.app.config
DestinationName: project.exe.config
I also tried:
FileFolderName: $(currentDir)\project.ev1.app.config
DestinationName: project.exe.config
This failed during deployment with the message:
The following command failed with the exit code '1' : powershell -command ./ManageWindowsIO.ps1 -Action Rename -FileFolderName 'project.ev1.app.config' -DestinationName 'project.exe.config'
Any ideas why such a simple command wouldn't be working?
Thanks
Can you run this exact command in powershell console ? You can also click on the button next to the command in the release log to grab a better detaild log whith explanation what went wrong .
The file could be in use , or without proper permissions for modification , you can look for the agent's logs in the target machine .
By the way if you are trying to make a file changed to the name of a configuration file for a win service or want to use transformation in a non web application you can use slow cheetah to accomplish it .

Nunit TestResult.xml is not created during Jenkins build

To run tests in Jenkins I use the next batch command:
"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" /result:TestResult.xml "C:\Users\Denis\Documents\Visual Studio 2013\Projects\MyProject\App.nunit"
Here how it looks in Jenkis:
The problem is: it doesn't generate TestResult.xml file!
When I run the same command as a .bat file from my desctop it creates the TestResult.xml file.
Any ideas what is wrong with Jenkins?
P.S. I searched for created file in all possible folders and even via "search"
I came up with thought that the file is generated and removed then or something like this.
The thing is that I don't see this file indeed but Jenkins generated report based on this file! So I think maybe after generating report the file was removed automatically.
I had faced the same issue and I found the test results xml file under my user directory in Win 7.
Note : I think it's some problem with nunit that it doesn't export the file to the location of which we provide the path.

NSIS simple copy one file from another folder in program files directory to installation dir not working

I tried to create an installer to install a application.
The basic stuff works fine, but I have problems, when it comes up to simply copy an existing files, which is located in some subfolder of Program Files folder.
The scenario behind this, is that the application has different versions and a license file.
When the app gets installed, the installer looks for an existing file, and if exists, should just copy that license file to the $INSTDIR/license folder.
Example:
C:\Program Files (x86)\MyApp\Ver1.0\license\ // here's the location of old license file
C:\Program Files (x86)\MyApp\Ver2.0\license\ // here to put the old license file
Following section is condensed to the relevant stuff:
Section "License of other Version"
IfFileExists '$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc' beginLicense endLicense
Goto endLicense
beginLicense:
MessageBox MB_OK "We have found an old license file. Do you wanna to use it for current installation ?"
CreateDirectory "$INSTDIR\license"
CopyFiles "$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc" $INSTDIR/license/some_license.slc"
endLicense:
MessageBox MB_OK "There were no license found."
SectionEnd
The compiling runs fine, but the installation process denotes an error when trying to copy the file. But it gives no further explanation, why it failed.
I tried also using the File directive, but that produced other errors, because of using the constants in file directive (file not found, and that sort of errors) and even the script cannot compile.
I tried also using a macro, mentioned here in another question of stackoverflow (sry, didnt have the link anymore), but it didnt worked for me, too.
What am I doing wrong, is it not allowed to use constants in CopyFile directive ?
Any help is appreciated.
You need to change:
CopyFiles "$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc" $INSTDIR/license/some_license.slc"
To:
CopyFiles "$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc" $INSTDIR\license\some_license.slc"
NSIS is not a fan of / slashes. While most of the low-level kernel32 functions can handle them, not all things in the shell can and that probably includes SHFileOperation used by CopyFiles. Even if that was not the case, internal path processing in NSIS tends to eat / slashes...

Run .bat as a Windows Service

I'm here again with another case that is getting me out my mind.
So, this is happening, I'm trying to run an executable java class(.jar) as a Windows Service, and all my attempts failed so far. To make it a little easier, I turned my jar into a batch file, wich only executes the jar in background, here is the code:
start "" javaw -jar C:\LocalService.jar
The batch works fine. However I have tried to install this batch as a service by using the next line in cmd:
sc create "LocalService" binPath= "C:\LocalService.bat"
The Service installs correctly, but as soon as I try to start it, it pops up an error (The code error is 1053, says something about the service did not start correctly)
Also, I have try with a software called NSSM (non-sucking service manager) It installs fine too, but the service does not start either.
Do you guys know what am I missing?
By the way, I'm doing all this on Windows 7 Professional.
Thanks!
thanks for your comments
Both tools didnt work for me, sadly. However I was able to do it with a software called Java Service Wrapper. This is not a free software, so I needed to buy a license to get it to work.
The steps were simple:
1.-Create a folder with the name of the service, then inside add 4 folders: lib,bin,logs,conf
2.-On the lib folder you have to copy your jar and also the wrapper.jar and wrapper.dll (these last two are in the zip you download from the website)
3.-Copy 4 files to the bin folder: InstallApp-NT.bat.in, App.bat.in, UnintstallApp-NT.bat.in and wrapper.exe (this last one is the one that defines your license, if you can get a file wrapper.exe from somebody else who had paid a license it will work fine. These file also came in the zip from the website) Remove the .in from the batch files
4.-The most tricky step is this: You have to copy from the wrapper's folder called conf a file called wrapper.conf.in Remove the .in extension and edit it with a tex editor. The most important lines you have to edit are:
wrapper.java.command=C:\Program Files (x86)\Java\jre7\bin\java //Specify JRE Path. Will work with eviroment variable
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperJarApp //Choosing this class means your are using a .jar file to execute when the service starts
wrapper.java.classpath.1=C:\LocalService\lib\wrapper.jar //This one is constant.
wrapper.java.classpath.2=C:\LocalService\lib\LocalService.jar //This is the path to your executable jar
wrapper.java.library.path.1=C:\LocalService\lib //Path to your own lib folder (the you created at the begining)
wrapper.app.parameter.1=C:\LocalService\lib\LocalService.jar // again the path to your jar
Then just execute the InstallApp-NT.bat and start the service and your are done
It worked to me with absolute paths, however according to documentation it will work fine with relative path too.
This is how I solved my problem and I hope someone with the same issue will find this helpful
See you next time!

Resources