How to Trigger Recycle with MSBuild? - iis

I use MSBuild to publish a project to a website using the file system. Is there a way to trigger a recycle? It appears that sometimes this causes the Integration Tests to fail depending on the changes because a recycle is not done. This is the web client project but we have additional projects with the exact command used the same way for the project. We are using IIS 8+. This is done VIA command line, any alternatives, maybe edit the web.config manually VIA command line after the MSBuild publish?
"%SOAB_MSBUILD_EXE%" "%SOAB_LOCAL_APP_PATH%\WebClient\WebClients.csproj" /p:Configuration=Debug /p:VisualStudioVersion=16.0 /p:Platform=AnyCPU /t:WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=C:\inetpub\wwwroot\CI\WebClient
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

Related

Hot deploy of JSF pages in NetBeans to JBoss standalone

Background
Here's the set up:
Multi-developer environment using Subversion
NetBeans 8.0.2
JDK 1.7
Java EE6
JBoss 6.2 EAP running standalone
We may not change the tools; we may use neither Maven nor JRebel. Hardware upgrades are also not in scope.
Code Organisation
The source code, including web-related files, are checked out into:
C:\Apps\07-Work\Project\Project-Admin\Project-Admin-User-war\
This directory includes a common development structure (bold are checked out from the repository):
build - compiled files
dist - .war file
nbproject - project files
src - Java source code
web - JSF pages, WEB-INF directory, CSS files, etc.
build.xml - Ant script
JBoss Installation
The web application server is installed into:
C:\Apps\04-Tools\jboss-eap-6.2
Problem
The develop - deploy - test cycle is painfully slow. It can take upwards of 30 seconds to test a single change to a web page. Here's the current flow:
Edit file in NetBeans.
Save file.
Shift+F11 (Run >> Clean and Build).
Switch to browser tab (http://localhost:9990/console/App.html#deployments).
Click Replace.
Click Choose File.
Select Project-Admin-User-war.war file.
Click Open.
Click Next.
Click Save.
Switch to browser tab (http://localhost:8080/admin/users/).
F5 to reload the page.
The build (step 3) takes about 26 seconds; manual deployment adds to that.
Here's the ideal development cycle:
Change a JSF page in NetBeans (note: this is a file checked out from repository).
Save the JSF page.
Alt+Tab to a browser window.
F5 to reload the page.
It isn't as important to have hot deploy on Java source changes, as code development time tends to take much longer than simple web page layout changes.
Editing the exploded contents would mean developers are no longer editing files checked out from the repository and would therefore incur additional steps, or scripts, or possible loss of work.
Others have suggested the Deploy on save feature, which is disabled:
Another suggestion (as per the screen shot) is to run the application in debug mode, but selecting Debug >> Project (Ctrl+F5) didn't show page updates after changes.
Question
Is hot deploy of JSF pages possible using the given tools and constraints? If so, what are the exact steps required to achieve the ideal development cycle?
Standalone Configuration
The README.txt file shows that it is possible to "live deploy" content:
H) Manual mode only: Live replace portions of currently deployed unzipped content without redeploying:
cp -r target/example.war/foo.html $AS/standalone/deployments/example.war
Where the cp command on Windows translates to:
xcopy /e /s /y src dest
This leads to:
Open a command prompt.
Change directory: cd C:\Apps\04-Tools\jboss-eap-6.2\standalone\deployments
Create skipdeploy to prevent deployment while copying is in progress: type nul >> Project-Admin-User-war.war.skipdeploy
Copy files to create a directory containing the files that have changed:
xcopy /i /y /e /s C:\Apps\07-Work\Project\Project-Admin\Project-Admin-User-war\web Project-Admin-User-war.war
Next:
Delete skipdeploy: rm Project-Admin-User-war.war.skipdeploy
Create dodeploy: type nul >> Project-Admin-User-war.war.dodeploy
Return to the browser.
Press F5 to refresh.
The result is that a resource bundle has gone missing:
Related
Is it possible to deploy an exploded war file (unzipped war) in JBoss AS 7
How can I get JBoss to explode a deployed WAR file?
Jboss step by step set hot deploy
https://jasonmarley.wordpress.com/2014/09/11/how-to-deploy-exploded-archives-jboss-eap-6/
Here is a description of a Ant script change from 2009 found on http://wiki.netbeans.org. Maybe it is useful still.
http://wiki.netbeans.org/TaT_DeployOnBuildUsingJBoss
And another script solution:
How to setup JBoss server with Netbeans?
Overview
Achieving hot deploy using JBoss 6.2 EAP running in standalone mode is accomplished in three parts: configuration, exploding, and hot deployment.
Configuration
Ensure that a deployment scanner is configured as shown:
Ensure the web subsystem and system properties are configured:
Stop JBoss.
Edit %JBOSS_HOME%\standalone\configuration\standalone.xml.
Immediately after </extensions> (before <management>), disable caching:
<system-properties>
<property name="java.net.preferIPv4Stack" value="true"/>
<property name="org.jboss.as.web.deployment.DELETE_WORK_DIR_ONCONTEXTDESTROY" value="true"/>
</system-properties>
Find the web subsystem (e.g., xmlns="urn:jboss:domain:web...).
Append the following element:
<configuration>
<jsp-configuration development="true"/>
</configuration>
Save the file.
Start JBoss.
Exploding
Exploding requires extracting the full contents of a WAR file with contents that will be deployed in the (very near) future.
Clean and build the application (Shift+F11 in NetBeans).
Change to the JBoss standalone deployments directory.
Create a skip deploy file.
Create the WAR directory.
Extract the WAR file.
Delete the skip deploy file.
Create the do deploy file.
This resembles the following (on Windows platforms; substitute paths for %JBOSS_HOME% and %PROJECT_HOME% as required):
cd %JBOSS_HOME%\standalone\deployments
type nul >> Project-Admin-User-war.war.skipdeploy
mkdir Project-Admin-User-war.war
cd Project-Admin-User-war.war
jar -xvf %PROJECT_HOME%\dist\Project-Admin-User-war.war
cd ..
del *skipdeploy
type nul >> Project-Admin-User-war.war.dodeploy
Hot Deployment
Create a batch file that contains the following:
cd %JBOSS_HOME%\standalone\deployments
type nul >> Project-Admin-User-war.war.skipdeploy
xcopy /i /y /e /s %PROJECT_HOME%\web Project-Admin-User-war.war
del *skipdeploy
type nul >> Project-Admin-User-war.war.dodeploy
Web Development
The ideal development cycle has almost been achieved:
Edit file in NetBeans.
Save file.
Run batch file.
Alt+Tab to browser.
F5 to refresh.
Ant has an OnSaveTask that can likely be coerced to run the batch, or even substitute for the batch file completely. Left as an exercise for the reader.

Jenkins build Visual Studio Solution with Different Configuration

Hi I have a visual studio solution which has been configured in Jenkins. And it's building successfully in debug configuration. How ever I need to change the build configuration to Release or another different one.
So How can I configure Jenkins to select the configuration to build?
If you are using the MSBuild plugin, try adding the configuration flag on the "Command Line Arguments" section:
/p:Configuration=Release
If you are simply building from command line script (batch, powershell, etc), add the above flag there..
What I do, is create a generic job for build process which receives a parameter called "BUILD_CONFIGURATION" from the parent job which triggers it.
And I then reference it in the flag as a variable:
/p:Configuration=${BUILD_CONFIGURATION}

Run PreSync/PostSync commands via WPP deploy.cmd

I'm trying to figure out how to run a pre/post command using the deploy.cmd generated by VS/MSBuild. I understand there are pre/postsync commands which can be set on the command line with msbuild but this is fixed within the web deploy package inside of the x.deploy.cmd.
How do I go about customizing the output of this file so that I can run the deploy command with specific parameters?
The intention is a non-developer will pick up the package zip file and import the application into IIS. We use IIS to host some windows services and so to be able to deploy we need to stop and uninstall the service before deployment and then install restart in the post deploy stage.
For certain servers we allow auto deployments from TFS and hook this pre/post command using the .targets file of the msbuild WPP pipeline. However, we want to this to be available to the manual deploy command files.
PreSync/PostSync are features of the msdeploy command line and are not supported by the package/manifest providers, or even the API. They are equivalent to running msdeploy a second time, so there's no way you'll be able to include their functionality while directly importing the package into IIS.
I'd recommend having a batch/powershell file on the server that the user runs after copying the package into the same directory.
The .cmd file that MSBuild generates is boilerplate script that you can simply change to call your pre/post powershell scripts. Just overwrite the one generated by the build with your custom one.

How can I get Unit Tests to run against the appropriate DLL when the DLL cannot be referenced in the project?

I've got the following "Pre Build Event" working for my powershell builds (including our Continuous Integration). It simply moves a DLL into the output directory based on the Processor Architecture.
if '$(PROCESSOR_ARCHITECTURE)'=='AMD64' (copy /y "$(ProjectDir)x64\sqlite3.dll" "$(OutDir)")
if '$(PROCESSOR_ARCHITECTURE)'=='x86' (copy /y "$(ProjectDir)x86\sqlite3.dll" "$(OutDir)")
if '$(PROCESSOR_ARCHITEW6432)'=='AMD64' (copy /y "$(ProjectDir)x64\sqlite3.dll" "$(OutDir)")
The problem I'm running into is when I run the Resharper Unit Tests within the IDE. When I do this, the Pre Build event doesn't run, and therefore all of the tests that depend on the sqlite3.dll fail.
What I need to do is either be able to move the appropriate file into the output directory before the Test Runner runs, OR make sure the Test Runner runs against ONLY the x86 Architecture, whereby I can just drop the appropriate file in the bin\debug folder and be done with it.
Things I've tried:
I've tried setting the "Build Settings" to "Always Build" but this has no affect on the outcome. It appears as though the build in the IDE doesn't run the Pre Build Event
I've also tried to set the default platform architecture in [Resharper -> Options -> Tools -> Unit Testing] - as per the docs, but unfortunately my version of R# doesn't have that option (7.1.3)
You can force the C# project to be 32 bit only, and the ReSharper runner will only run it as 32 bit. That way, you can drop the x86 dll in the bin\debug folder and it should all just work.

How do I fix MSB3073 error in my post-build event?

I'm working on a project that requires that DLLs generated by building my solution to be copied from the bin folder to another folder, both of which are on my machine, in my C drive. I've written a batch file that uses xcopy to accomplish this, which you can see here:
xcopy /s /y /q "C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.dll" "C:\inetpub\wwwroot\AppServer\bin\"
xcopy /s /y /q "C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.pdb" "C:\inetpub\wwwroot\AppServer\bin\"
Now, I've tried numerous iterations of this file, which is located at:
C:\Users\scogan\Desktop\CopyFiles.bat
so my post-build event command line looks like this:
call C:\Users\scogan\Desktop\CopyFiles.bat
I've run this batch file on its own with two text files in folders on my desktop, and it works fine. I've also run it as it is with the files I need to copy on its own, and that works fine, too. However, when I try to run this as a post-build event, I get this output:
1> Organizr -> C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Client\bin\Debug\Organizr.exe
1> File not found - Organizr.Services.dll
1> 0 File(s) copied
1> 0 File(s) copied
1> File not found - Organizr.Services.pdb
1>c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4291,5): error MSB3073: The command "call C:\Users\scogan\Desktop\CopyFiles.bat" exited with code 4.
I've done some research, and found that error code 4 means that "Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line."
I've also looked up what MSB3073 is, and haven't really found much that can help me there. So, my question is what am I doing wrong? Are the absolute paths messing it up? Any help here is appreciated.
Playing around with different project properties, I found that the project build order was the problem. The project that generated the files I wanted to copy was built second, but the project that was running the batch file as a post-build event was built first, so I simply attached the build event to the second project instead, and it works just fine. Thanks for your help, everyone, though.
Prefer the MsBuild "Copy" task in an AfterBuild target over a post-build event.
Append this Target into your project file and remove the PostBuildEvent.
<Target Name="AfterBuild">
<Copy SourceFiles="C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.*"
DestinationFolder="C:\inetpub\wwwroot\AppServer\bin\"
OverwriteReadOnlyFiles="true"
SkipUnchangedFiles="false" />
</Target>
For what it's worth, the problem in my case was caused by using '/' as the directory separator in a copy command. Must use backslashes.
In my case, the dll I was creating by building the project was still in use in the background. I killed the application and then xcopy worked fine as expected.
The specified error is related to the post built event. Somehow VS tool is not able to copy the files to the destination folder. There can be many reasons for it. To check the exact error cause go to Tools > Option> Project and Solution > Built and run, and change "MsBuild project build output verbosity" to "Diagnostic". It will give you enough information to detect the actual problem.
This is too late but posting my experience for people looking at it later:-
In MS VS 2010 I had the same issue. It got resolved by putting quotes to post build copy command args which contained spaces!
In Project Properties --> Configuration Properties --> Build Events --> Post-Build Event --> Command Line change:
copy $(ProjectDir)a\b\c $(OutputPath)
to
copy "$(ProjectDir)a\b\c" "$(OutputPath)"
If the problem still persists even after putting the after build in the correct project try using "copy" instead of xcopy. This worked for me.
The Post-Build Event (under Build Events, in the properties dialog) of an imported project, had an environment variable which was not defined.
Navigated to Control Panel\All Control Panel Items\System\Advanced system settings to add the appropriate environment variable, and doing no more than restarting VS2017 resolved the error.
Also, following on from #Seans and other answers regarding multiple project races/contentions, create a temp folder in the output folder like so,
and select the project producing the preferred output:
and build (no rebuild/clean) is a speedy solution.
Following thing you should do before to run copy command if you facing some issue with copy command
open solution as a administrator and build the solution.
if you have problem like "0 File(s) copied" check you source and destination path. might you are using wrong path. it would be better if you run the same command in "command prompt" to check whether it is working fine or not.
I solved it by doing the following:
In Visual studio I went in Project -> Project Dependencies
I selected the XXX.Test solution and told it that it also depends on the XXX solution to make the post-build events in the XXX.Test solution not generate this error (exit with code 4).
I've found the issue happens when you have multiple projects building in parallel and one or more of the projects are attempting to copy the same files, creating race conditions that will result in occasional errors. So how to solve it?
There's a lot of options, as above just changing things around could solve the issue for some people. More robust solutions would be...
Restrict the files being copied i.e. instead of xcopy $(TargetDir)*.*"... instead do xcopy "$(TargetDir)$(TargetName).*"...
Catch the error and retry i.e:
:loop
xcopy /Y /R /S /J /Q "$(TargetDir)$(TargetName).*" "somewhere"
if ErrorLevel 1 goto loop
Use robocopy instead of xcopy
You probably won't want to do this as it will increase your build times, but you could reduce the maximum number of parallel project builds to 1 ...
I had the same problem for my Test project. I found out why my post build event wasn't working and that's because I was copying files before running the $(ProjectName).exe command and some of these files were required for Test project itself. Hence, by just moving $(ProjectName).exe as the first command fix the issue.
I faced this issue recently and surprisingly only i was having this problem and none of my team members were facing this issue when building the project code.
On debugging i found that my code directory had spacing issue , It was D:\GIT Workspace\abc\xyz.
As a quick fix i changed it to D:\GITWS\abc\xyz and it solved the problem.
I was getting this error after downloading some source code from Github. Specifically the rust oxide development framework. My problem is that the Steam.ps1 script file, that's used to update some of the dlls from Steam was blocked by the OS. I had to open the files properties an UNBLOCK it. I had not realized this was done to ps1 files as well as exes.
In my case a setting mismatch between Project's Configuration Properties->General->Output Directory setting and Linker->General->Output Directory.
There was a warning about it during linking.
I was facing a similar issue where it said it cannot copy a DLL from my build location to destination. The issue was my project path contained spaces, removing them the error was gone.

Resources