Visual Studio create ZIP on branching (build process?) - visual-studio

Let's say I got a TFS with a team project and in this team project I got many folders (projects). In every project I got a branching structure so I have the folders main, servicing, hotfix and release.
I need to create a zip file whenever I take a branch to the 'release'-folder.
Is there a way to create a zip file from a project in my 'release' directory within the branch process?

If you wan to zip file during or after the merge. It's impossible.
What you can do is zip files of the build output. And then copy to the release folder.
You need to add a PowerShell script to achieve it.
For XAML build :Add the post script
For VNext build: Add the powershell script step
Access the variables using $env:. The drop location would be $env:TF_BUILD_DROPLOCATION
A example:
function create-7zip([String] $aDirectory, [String] $aZipfile){
[string]$pathToZipExe = "C:\Program Files\7-zip\7z.exe";
[Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
& $pathToZipExe $arguments;
}
create-7zip "$Env:TF_BUILD_BINARIESDIRECTORY\x86\Release\*" "$Env:TF_BUILD_DROPLOCATION\x86\Installer.zip"
create-7zip "$Env:TF_BUILD_BINARIESDIRECTORY\x64\Release\*" "$Env:TF_BUILD_DROPLOCATION\x64\Installer.zip"

Related

Azure DevOps Build Task: create a zip with contents identical to Visual Studio Publish

In Visual Studio, when we publish to a folder, that folder contains exactly what we need to deploy.
In Azure Pipeline, the Build Solution task produces a a bunch of (to us) unnecessary files plus a zip file (nice!). The zip contains the files we need, but buried in an crazy deep folder path:
\Content\D_C\a\1\s\src\MyProject\obj\Release\Package\PackageTmp\our-files.dll
What we would prefer is:
\our-files.dll
It also modifies connectionStrings in the web.config to support the deploy script it ships with. We don't need that script and that modification is a pain (which we disabled by adding<AutoParameterizationWebConfigConnectionStrings>false</...> to the .csproj file - yuck!)` .
We tried fussing with the parameters in the Build Solution step:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Changing DeployOnBuild to false caused the $(build.artifactsstagingdirectory) to be empty (causing the next step to deploy nothing)
Changing WebPublishMethod to FileSystem made no difference (try finding documentation on the allowed values!)
Changing PackageAsSingleFile to false did what one would expect - no zip, but the contents were still buried in that deep folder structure.
Our downstream script could open the manifest file, xpath out the deep path baked into the zip (does the path always start with d_C?), unzip and grab the contents from there - but what a pain and how unnecessary.
Is there a way to publish just a nice clean build - a zip with contents that directly unpacks to the same files as a plain-jane Publish from Visual Studio does?
In the Visual Studio Build step change "MSBuild Arguments" to
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\" /p:UseWPP_CopyWebApplication=true /p:OutDir="$(build.artifactstagingdirectory)"
The key thing is /p:OutDir="$(build.artifactstagingdirectory)" resolves the directory issue and /p:UseWPP_CopyWebApplication=true removes web.config.release and web.config.debug
Then update Publish Build Artifacts step "Path to publish" to
$(build.artifactstagingdirectory)\_PublishedWebsites

TFS 2015 - Build solution, package project. Also building a solution it shouldn't be

I have a solution with 8 projects in it and only 1 of them is a web site/app. The rest all create assemblies that are referenced in the web app.
I want to build the solution and then package the web site project into a web deploy package.
So in TFS, I've added the Visual Studio Build step (no other steps in the definition after this), pointed it to the solution and added the following MSBuild arguments:
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
Note that in TFS source control, there are 2 solution folders. For this build, I just want to build one of the solutions. So I've given it the full path to the solution I want (without any wildcards).
The build succeeds and when I look in that directory (\TfsData\Build_work\1), it has created 4 folders in there: 'a', 'b', 's' & 'TestResults'.
Folders 'a', 'b' & 'TestResults' are empty.
The 's' folder has a '$tf' folder with a bunch of stuff in there that I don't know what it's for.
The 's' folder also has BOTH solutions in there. I don't want the second solution build/placed there. Just the first one.
And I can't find any web deploy (zip) packages for the web app in the first solution. It's just the built folders.
S stands for Build.SourcesDirectory
The local path on the agent where your source code files are downloaded. For example: c:\agent\_work\1\s
A stands for Build.ArtifactStagingDirectory
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent\_work\1\a
B stands for Build.BinariesDirectory
The local path on the agent you can use as an output folder for compiled binaries. For example: c:\agent\_work\1\b.
According to your description, you need to cloak folders you don't need in source mappings under Repository of your build definition.
Besides, you have to use Copy and Publish Build Artifacts to publish your build artifacts to drop folder(sever path) or a shared path.

Failed to find Visual Studio .sln file - Dynamic parameter for build step template

I am fairly new to using TeamCity. We are currently using 9.16.
I am trying to setup a build template to associate across our many projects and I keep getting the error "Failed to find Visual Studio .sln file" for both the NuGet Installer step and Visual Studio (.sln).
Currently it is set to %system.teamcity.build.checkoutDir% and it says there is no *.sln file there, but there is when I look at the build server directly.
Failed to find Visual Studio .sln file at C:\TeamCity\buildAgent\work\58ef95107452dcbc\*.sln
I found the post regarding attaching the VCS root, but I do have that attached and it mirrors the projects that currently do not use a template.
Any help as to what I am missing would be greatly appreciated.
You must put the filename of your visual studio solution file in the "Solution file path" field of the "Visual Studio (.sln)" build runner step.
If your .sln file is at the root of your checkout directory you would specify the filename. Example: YourSolution.sln
For the "Nuget Installer" build runner step you must put the same solution filename in the "Path to Solution File" field.
Note that if your solution file is not in the root folder of your checkout folder you must specify the relative path. Example: path/to/my/SolutionFile.sln
What I was attempting to do is not possible.
Instead I created a parameter at the root level for SolutionFile in the templates. Then I simply change the value of that parameter in each project that uses the template.
In my case I was moving from SVN to GIT with TeamCity, and so had to change the VCS root from:
http://build.server.url:81/svn/MyApp/
To,
http://Build-Server-User#git.build.server.url:7990/MyApp/MyApp.git
Also, I had to change "checkout rules" from:
+:trunk => .
To,
+: => .
Because the default branch in TeamCity for GIT is refs/heads/master
For details, please see https://confluence.jetbrains.com/display/TCD10/Git

how to automatically add files to a visual studio project in a pre-compile step?

I have a perl script to copy some files into my project directory . The pre-compile step of our project will run the script. But the problem is that copied files are not add to the project dependency automatically . Is there a way to add them by automation ?
The copying and running of the scripts can be done by using the Pre Build and Post Build macros. Also the DTE provides things such as BuildEvents. Take a look here.

What's the easiest way to install 100s of files in a Visual Studio setup project

I have a standard c# application that acts as a GUI front end for a an "R" statistics engine. "R" consists of approx 600 files in approx 50 different folders and can be "installed" on a machine through xcopy deployment.
I would like to package up both the R engine and my c# gui into one setup.exe so that the user doesn't need to go and install R first and then my c# application seperately.
I know that I can produce a setup project and then add in the R files one by one but adding all 600 files will be very tedious!
Is there an easier way of doing what I want? Can I add the single R folder and automatically add the subfolders and files to save me adding them in one by one? Or maybe do an unzip procedure in my setup project which will unzip the R engine in one go?
You can simply drag/drop the folder in Windows Explorer into the File System view of your Installer vdproj. All the files and folders in the hierarchy will be added to your setup project.
Tip: If the folders are in SVN or similar source control, delete all the hidden folders before you do this! If you have PowerShell, check out
get-childitem . -include _svn -force -recurse | foreach ($_) {remove-item -recurse -force $_.fullname}
Or you can always use Windows Search to find all hidden directories in the hierarchy and delete them from the Results Window.
I couldn't work out the project file so what I did in the end was to zip up all the files I wanted to deploy, add the zip file to the application and create a custom Installer class to unzip them (using CSharp ziplib)
I think Badjer is most of the way there.
If your 600 files are part of a project and the "Build action" for each of these is set as content you can add all of these by simply:
Going to the setup project
Selecting Add > Project Output
Selecting the project the files belong to from the drop down
Selecting the "Content Files" option from the list below
Clicking OK.
You can check the files will be added to the appropriate place by going to View > File System on the setup project and checking that the content files output is being added to the correct folder.
The files will be added to the install directory in the same hierarchy as they are specified in the project they belong to.
Have a look at the project file. I believe is text based. You might be able to insert the file paths directly there with some copy-paste-replace.
One thing you could try is adding the R files as content in the C# project - then the setup project can just copy them over for you (make sure you configure the setup file to copy content files from your project, not just the primary output).
You can either add the R folders into the project manually, or set up a script to modify the .csproj file (it's just an XML file) - content items are represented by these nodes:
<Content Include="myfile" />

Resources