Copy file to the App Resources directory if debug configuration is selected - iphone

I need to copy a few files into the App's Resources directory during debug builds. I am thinking about using build rules but don't know how to determine if the build is a debug build. I do have a compiler option of "DEBUG" set.

You can use a Run Script build phase to do the copying. All build settings applied when building the target are available via environment variables in your script.
You can determine what configuration is being built via the CONFIGURATION environment variable; you can look at other environment variables like BUILT_PRODUCTS_DIR to determine where to put your resource. If you specify your Run Script build phase's output correctly, it will only be run when the output needs to be brought up to date, not every time you build.
More information on Run Script build phases is available here: Xcode Build System Guide: Build Phases: Run Script Build Phase
The same kind of thing can be done with script build rules, which is useful if you have multiple resources you want to apply this to: You can create a script build rule that matches your extension (e.g. *.myresource) and use the build settings and input files that are passed to your script via environment variables to do the actual copying. If you specify your build rule's output correctly, it will only be run when its input is newer than its output, not every time you build.
More information on script build rules is available here: Xcode Build System Guide: Build Phases: Build Rules

Related

Codemagic - Set Dynamic Environment Variables for the Build arguments

I am looking a way to manage dynamic environment variables in my build arguments.
I am able to make it work if I define values for TARGET_FILE and FLAVOR in the environment variable section in CodeMagic.
But my goal is to have the values specified in my git repository. So I will be able to change it and have a dynamic build.
I was thinking I would be able to set the env var in the pre-build section.
Following is a sample of my pre-build.sh file
# in my case it’s `dev`, `qa` and `prod`
export FLAVOR='qa'
# major and minor part of app version e.g. 1.0
export VERSION_NUMBER='1.0.0'
# this is the entry point of the app e.g. main_dev.dart
export TARGET_FILE="lib/main_$FLAVOR.dart"
My build is still failing because the TARGET_FILE for example is not specified
Target file "--flavor" not found.
Build failed :|
Failed to build for Android
I was wondering if anyone has ever encountered this scenario
As for configuring build from GitHub you can use codemagic.yaml file that allows you to define the configuration for CodeMagic build, including env variables (here is a docs).
Additional notes, just a proposition))
I actually don't know what is going on in your Flavors and env entry points, but quite possible you can actually get rid of both.
For instance, you can use .env file and flutter_config package to pass env specific variables to the native layer, including plist's and Gradle. Also, you can load this .env file into Dart code and use variables from it. On top of this, you can use this package to generate .env file with the terminal command (if you don't want to create any sh scripts))). Alongside with .env file, it can generate Dart class specifically for Dart code. It also can generate files based on global env variables.
In that way all environment specific configuration will be defined once, you won't expose your prod credentials anywhere except build tool and you won't need to copy/paste multiple entry points.
Update 08/05/2020:
Starting from Flutter 1.17 you can use --dart-defines argument instead of environment_config and flutter_config package to define compile-time variables. You can read more about this argument here

vNext build System.Activities.statements.writeline

I am tasked with writing a file to include with the source code after a build.
With xaml, I used System.Activities.statements.writeline so that I could bundle everything in the build template. I know that I can use PowerShell or a batch to achieve what I need however I do not have access to the build box and I do not want to force my developers to include files not associated with the application in source control.
Is there a way to create a file and add text with a build task and not be dependent on anything other than the build tasks?
Thanks,
Use the PowerShell task and choose "Inline Script". You can then write any script you want in there.
However, I'd make the case that it should be source controlled. Files required for your build and deployment processes are part of the application, if you think in terms of DevOps.
You can custom build task and do that in the build task script directly.
Add a build task

Is there an environment variable or way to get custom task directory in VSO Build?

So I'm trying to get the custom build task directory name from powershell when executing a custom build task.
The purpose is that I want jshint to run on build time, and I've got it doing so, but the .jshintignore file needs to know a relative path to exclude files or folders.
So I need be able to get that path at runtime in order to know how many "../" to add on to the excluded files for the minmatch engine, which is what jshint uses, to match them.
I can, of course, hard code it, but that's really not what I'd prefer to do.
Yes, you can use the Agent.HomeDirectory variable.
Agent.HomeDirectory | AGENT_HOMEDIRECTORY | The directory the agent is
installed into. This contains the agent bits
The tasks folder will be $(Agent.HomeDirectory)\tasks(TaskFolder)\

TFS Build Website deployment package web.config transformation not working

So I am trying to use TFS Build for generating deployment packages for my 3 environments (ST, UAT, Prod).
This what I followed to successfully genrate the package locally.
http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/74bb16ab-5fe6-4c00-951b-666afd639864/
So my local machine will generate the package for the acyive configuration and everything is good. Here is my Build definition :
/p:DeployOnBuild=true;DeployTarget=Package
I run my solution file and the web deployment project in the Projects To Build.
It creates the respective folders with ST, UAT and PROD. In each of these there is a _PublishedWebsites folder. This folder have 2 folders.
1) MydeploymentProject - It contains the transformed web.config
2) MyDeploymentProject_Package - Contains the Package folder contents along with the zip file and setparameters files. Here the everything is not transformed. But if I check the TempBuildDir on the TFS server it does contain the transformed config.
When compared the logs local and on server, I found that the on my local After transformation files are updated and package is created whereas on TFS the AfterBuild target is called transformation done and it ends there.
this is my local log
Target "WPPCopyWebApplicaitonPipelineCircularDependencyError" skipped, due to false condition; ($(WPPCopyWebApplicaitonPipelineCircularDependencyError)) was evaluated as (False).
Target "ProcessItemToExcludeFromDeployment" in file "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" from project "C:\TAX-IT\Main\Source\TDDB\TDDB_deploy2\TDDB_deploy2.wdproj" (target "PipelineCollectFilesPhase" depends on it):
Done building target "ProcessItemToExcludeFromDeployment" in project "TDDB_deploy2.wdproj".
Target "GetProjectWebProperties" in file "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" from project "C:\TAX-IT\Main\Source\TDDB\TDDB_deploy2\TDDB_deploy2.wdproj" (target "PipelineCollectFilesPhase" depends on it):
Using "GetProjectProperties" task from assembly "C:\Program Files\MSBuild\Microsoft\WebDeployment\v10.0\....\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll".
Task "GetProjectProperties"
I am not sure what is wrong.
Also I installed VS2010, web deploy 2.0 and 3.0 and web deployment tools on my Build servers.
Anyone have faced this and resolved.
Please help.
Thanks
MadCoder,
From what I've gathered from your description, you have everything set up correctly. It seems like you are just missing the "Configuration" parameter. When you do run the Build Definition, it uses the configuration specified in your "Configurations to Build" argument. If you want to have multiple configurations built (like you are suggesting), you'll need to have multiple configurations defined. One question I have is: When you look at the logs of the TFS Build Process, do you see multiple configurations built, or do you only see one? If you only see one, then you don't have all of the configurations defined in order to transform the config file. According to your description, you'll need to see something like this in your build definition configuration:
If you don't want to deploy to a webserver, you can stop reading here, and don't have to continue on.
If you choose to use a TFS Build Definition to deploy to a web server, you'll need to have a target web server somewhere and you'll need to install and configure the Web Deploy v2/v3 on that server as well.
When you are using TFS Build Definitions to deploy, the transformation happens upon deployment, not during packaging (prior to deployment). It may package up a transformed config somewhere, but it won't actually transform the config bundled with the website. The only way I've been able to get the deployment to actually work with a transformed config is when I had a website specified in the MSBUILD args. Here is an example of my MSBUILD args:
/p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MSDeployPublishMethod=RemoteAgent /p:MsDeployServiceUrl=MyWebServer/MsDeployAgentService /p:DeployIisAppPath="MyWebsite as named in IIS" /p:UserName=MyDomain\MyWebDeployUser /p:Password=MyWebDeployPassword
If you don't want MSBUILD to do the actual deployment (I prefer not to because then your deployment process is tied to TFS), you can do the deployment after the build process and use the CTT Project, found on codeplex. This tool performs the exact same transformations as MSBUILD, but it also includes the ability to parameterize settings so you can define classes of environments (for example, 3 QA environments, 2 Staging Environments, etc.) and still use the respective transforms for that class of environment.

Running script only for an 'Archive' build in Xcode 4

I have a script that I run using osascript from a Run Script Build Phase in Xcode 4. This script does some checks to try and catch any human-error in plists and suchlike.
However, I only really want to run this script when a developer chooses 'Archive' as opposed to running it every time they build.
Is there any way of testing for this situation? Either in Shell Script or Apple Script?
In Xcode 4+, you could run this script as a pre- or post-action script on the "Archive" action. However, pre- and post-action scripts are not considered part of the build itself; their output is not part of the build log, and a failing script will not cause the build to fail.
If you want to include this script as a first-class part of the build, such that its failure will cause the build to fail, then you'll want to do something else. Make a new "External Build System" target, and configure it to run your script. The path to your script can be a relative path, relative to the project root.
Finally, open your main project scheme, and in the "Build" tag add the new checker target, and set it to only be included in the "Archive" action. This should cause your checker script to be run as part of the build only when "Archive" is selected, and if the script returns a non-zero value the build will fail.
Here's a step-by-step visual guide to configure a bash script to run only when archiving a target:
File > New > Target > Other > External Build System
Name the product accordingly and set /bin/bash as the Build tool
Provide the path to the script under Info > Arguments of the newly created target
Product > Scheme > Edit Scheme…, and edit the scheme of the target where you want this script to run before archiving. Under Build, add the External Build System target you added in step 1. Reorder if needed. Then uncheck everything except Archive.
Add a "New Run Script Phase" to your project's "Build Phases"
Move (drag&drop) your script in the right position
Check the "Run script only when installing"
If you don't do 3. the script will run all the time, but if you check that box, it will only run when archiving.
So in latest Xcode (13.3) you can edit your schemes and copy & paste (or drag&drop) your executable script in the run script textfield (see image).
The pre-Action is executed before the Organizer is opened and the post-action is executed after the build landed in the archives list of products. In both cases the build process of archiving will run through beforehand.
A quick test on my own system shows no difference in the detailed script output between straight "Build" and "Build and Archive".
Also, you can't test for the presence (or absence) of the archive, since it only gets created at the very end of the process, when all scripts have been run.
As far as I can see, there is no current option within Xcode 3 to do this. Maybe file an enhancement request with Apple?
While you wait on Apple, the only solution I can offer is to use xcodebuild and xcrun as part of a command-line shell script, where you would know if you are archiving or not. This is not a stay-in-Xcode solution, but it does have a lot of flexibility.
Xcode "Build and Archive" from command line