This is my reference. So what we will do, is make the project build release and copy to specific directory which is build result files.
It will run only Windows Command line
.
- Open the command line console.
- Move to project folder which is same direction with [PROJECT-NAME].csproj
cd [PROJECT-DIRECTION]
- Build our project
msbuild [PROJECT-NAME].csproj /p:DeployOnBuild=true /p:PublishProfile=[PUBLISH-PROFILE-NAME] /p:Configuration=Release /p:AutoParameterizationWebConfigConnectionStrings=false
- Copy the result files
xcopy obj\Release\Package\PackageTmp [DIRECTORY-WHERE-YOU-WANT] /s /e
Done.
After we do is, if we commit changes to git server then auto build and deploy(File System) it. We will use git hooks. Reference git hooks ,msbuild options and precompile option
- Go to the project root folder which is in with
.git
folder
cd [PROJECT-DIRECTORY]
- Move to git hooks folder
cd .git\hooks
- There is some
.sample
files, open thepre-push.sample
file using notepad. - Write some script down below.
#!/bin/sh
echo "Move to working directory"
# change env
cd [PROJECT-DIRECTORY]
pwd
# build
echo "Clean obj folder"
rm -rf ./obj/Release
echo "Clean bin folder"
rm -rf ./bin/_PublishedWebsites
echo "Start to run publish process"
/C/Windows/Microsoft.NET/Framework64/v4.0.30319/msbuild.exe ./[PROJECT-NAME].csproj //p:OutputPath=bin //p:DeployOnBuild=true //p:Configuration=Release //p:AutoParameterizationWebConfigConnectionStrings=false //p:WebPublishMethod="FileSystem";PrecompileBeforePublish=true;EnableUpdateable=false;DebugSymbols=true;WDPMergeOption="CreateSeparateAssembly";UseFixedNames=true
cp -vr ./bin/_PublishedWebsites/[PROJECT-NAME]/* /[PATH-TO-WHAT-YOU-WANT]
echo "Done!"
exit 0
...And this is version of latest auto build script
#!/bin/sh
projectDir=
projectFile=
outputDir=
branch=
processResult=1
currentBranch=$(git branch | sed --quiet 's/* \(.*\)/\1/p')
echo "Project directory path: ${projectDir}"
echo "Project csproj name: ${projectFile}"
echo "Project output directory path: ${outputDir}"
echo "Git branch ${branch} : ${currentBranch}"
if [ $currentBranch != $branch ]; then
echo "Current branch[${currentBranch}] is not matching expected branch[${branch}]"
exit 1
fi
echo "Move to working directory"
# change env
cd $projectDir
pwd
# build
echo "Clean obj folder"
rm -rf ./obj/Release
echo "Clean bin folder"
rm -rf ./bin/_PublishedWebsites
echo "Start to run publish process"
/C/Windows/Microsoft.NET/Framework64/v4.0.30319/msbuild.exe ./${projectFile}.csproj //p:OutputPath=bin //p:DeployOnBuild=true //p:Configuration=Release //p:AutoParameterizationWebConfigConnectionStrings=false //p:WebPublishMethod="FileSystem";PrecompileBeforePublish=true;EnableUpdateable=false;DebugSymbols=true;WDPMergeOption="CreateSeparateAssembly";UseFixedNames=true
processResult=$?
if [ "${processResult}" != 0 ]; then
echo "Cannot build current project."
exit 1
fi
echo "Start to move build files"
cp -vr ./bin/_PublishedWebsites/${projectFile}/* $outputDir
processResult=$?
if [ "${processResult}" != 0 ]; then
echo "Cannot move build files."
exit 1
fi
echo "Done!"
exit 0