Copy app.publish folder in VSTS Build/Release - visual-studio

Similar to the question here: Copy one file in target directory on deploy from visual studio team services, I am trying to copy the contents of the app.publish directory of a ClickOnce application via VSTS build/release.
This is the Copy Publish Artifact step of the Build
This obviously outputs everything in the bin folder to the drop folder on the server share.
This is the Copy Files step of the Release
This copies only the files in the app.publish folder but it builds out the entire hierarchy to the folder app.publish folder; however, it builds out the full folder structure. i.e. bin\Release\app.publish or bin\Debug\app.publish.
I like the idea of being able to publish and store different configurations (debug/release) but I don't like that I'm having to specify the InstallUrl in the msbuild arguments in order to pick up debug/release in the folder path. Even if I didn't try to maintain multiple configurations, the configuration would still be in the path.
So my question is: Is there a way to use the copy files task to just copy the app.publish folder and/or the contents to another location, without it creating the full hierarchy?

You need to specify the copy root in Source Folder of Copy Files, in your example, the copy root should be like:
Source Folder: $(System.DefaultWorkingDirectory)\$(Build.DefinitionName)\bin\$(BuildConfiguration)\
Contents: **\app.publish\**
In this way, you should only have app.publish in your Target Folder.

Configure the "Copy Root" of "Copy Publish Artifacts" step in your build definition to the path of build configuration folder and "Content" to "**".
For example, if the path of your build output is:
C:\a\1\s\SolutionFolder\ProjectFolder\bin\Relase\app.publish...
You can set the Copy Root to:
$(build.sourcesdirectory)\SolutionFolder\ProjectFolder\bin\$(BuildConfiguration)
And Content set to:
**

Related

Hosted macOS Preview deploy ipa to App Center

I have set up a hosted mac os preview build for a Xamarin app. All the steps complete except for 'deploy ipa' The publish artifact says nothing will be added. Here is are the settings from the copy files to as well as the output
Seems you set the incorrect Source Folder or Contents pattern in Copy Files step. That caused no files were copied to target folder for publishing.
Please check the logs of Copy Files step to see if the *.ipa files are really copied to $(build.artifactstagingdirectory).
If no files copied, then just check the build logs to get the real working directory (Source Folder in copy step) and make sure the *.ipa files are generated in the directory. (By default it's $(system.defaultworkingdirectory) on my side.)
If the real working directory is just the Source Folder $(Build.SourcesDirectory) you specified in Copy step, then the problem should be the contents pattern.
Contents specify minimatch pattern filters (one on each line) that you
want to apply to the list of files to be copied. For example:
** copies all files in the root folder.
**\ * copies all files in the root folder and all files in all sub-folders.
**\ bin copies files in any sub-folder named bin.

VSTS Copy and Publish Build Artifacts copying the whole project instead of the necessary files

I am trying to copy my build to a particular drop location. But instead of copying the some important files and directories it is copying all the solution file and directories there like .csproj files and .csfiles and also all the folders present there.
I only want to copy dlls(projects dlls and references dlls of the project) and some data Folders and files to drop location so that I can use them to execute my test cases. But it ends up copying the whole solution.
Below are the setting I am using to copy and publish build artifacts.
Can Anyone tell me how can it be done?
Note: when I tried to put $(build.sourcesdirectory)\bin in the copy root it gave me an error that "Cannot bind argument to parameter 'Path' because it is null".
I also tried putting only **.dll in my contents but then it copies nothing. The folder created in drop location comes empty.
You're telling it to publish **/*test*.dll, from the root of the build agent. That minmatch pattern is saying "find everything in every subfolder that matches test.dll", so the results you're getting aren't surprising.
What you probably want to do is specify the path to the binary output location of your test projects. Without seeing the structure of your code or what MSBuild variables you're providing/overriding, it's impossible to give more guidance. Look at the documentation on pre-defined variables and that should give you some ideas.
In general, you want to set your output folder (via MSBuild arguments) to $(Build.ArtifactStagingDirectory), so only build outputs go there. Then you can use that as your Copy Root.

How to have msbuild copy files to output directory across references?

Suppose we have a project A with output directory bin/ and a project B with output directory test/bin/. Project A needs to have a certain configuration file copied to its output directory. Currently, this is being done by adding a pre-build event that looks like
COPY /Y "$(ProjectDir)..\config.ini" "$(TargetDir)"
Project B has A as dependency. When project B builds, the binary resulting from A is correctly copied to the output directory of B, but the config file isn't!
How can we achieve that all files that A needs to have are also copied to the output directory of B?
What you want is a Link File. I've used these before to ensure that connection.config files are copied to multiple projects.
I created a sample solution that mimics your described scenario as seen below. The ConsoleApplication1 references the ClassLibrary1 project. In the solution, I created a solution folder config and added the shared config that needs to be copied.
In order to have a single file that is copied across multiple projects, you must create a single file, and then add it as a link to the projects that need it. This can be done by right clicking on the project, and choosing Add -> Existing Item.... You will see a dialog as show below and you want to choose the Add as Link option from the dropdown instead of just Add.
Finally, edit the properties for the linked file to copy it to the output directory.

Build from a Solution folder into a specific subfolder of the output folder

I know how to move built .dlls to a folder using post-build events to copy the files, or using the output path setting.
Can I do something like that for all projects in a solution folder, where I wouldn't need to set up build events. I want all projects in a solution folder "SomeDir" to be moved to a "SomeDir" folder when built.
"SomeDir" would be the subfolder of the main output folder
Thanks

Where to store files in Visual Studio projects

Inside the project folder there is a "project's name" folder, Release and Debug folder. I'm right now working in debug mode and my files keep getting updated everytime i run it, and i copy it into the other 2 folders everytime to avoid confusion. Is this the right way to do it or is it enough if the files are in the main folder ?
If you have files in the project that need to be copied to the current output folder on build then select the appropriate options in the file's properties: select the file in solution explorer and then set the properties of that file:
Build Action: None
Copy to output directory: Copy Always, or Copy If Newer.
Thus VS will put the files in the right place on build. You do not need to maintain multiple copies.
If your program needs access to text files, images, etc. which are separated from the program's code, you can put these both into the debug or into the release folder.
Beware that if you modify these files into the debug folder, you must update the files into the release, and vice-versa. This is valid if you use to switch between the debug mode and the release mode. If you use only the debug mode as I do while I'm developing, you could put all the files in the debug folder only, and copy these files into the release folder only when you will end the development.

Resources