Add source files to cocoa project not intended for compile - cocoa

I'm writing a cocoa application which should copy files to a given directory. The files should be part of the app, but not compiled. I'm thinking of a folder, e.g. "MySources", where I want to add all .a, .m and .xip files, which should not be compiled. These files should be left as they are - so plain and editable text. Then my app provides a button and when a user clicks on that button, the app copies all files within the "MySources" folder to a given directory.

Add a Copy Files build phase, configure it to copy to the desired destination within the app bundle, and add the desired files to that build phase.

In Target > Build Phases remove the appropriate files in Compile Resources and add Copy Files build phases to copy the files to the destination locations in the bundle.

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.

How do I access a resource file in Xcode?

To access the resource file namefile from a program:
I ostensibly just need to check the box "target membership" to identify it as a resource file:
but this box is disabled.
What am I missing?
The helloworld target in your project is configured as a command-line tool (the square black icon that looks like a Terminal indicates this). Those compile to a single, standalone file thus Xcode cannot embed a resource file with it (which is why it's disabled).
You need to build a "Cocoa Application" target if you want to be able to include resource files. You can start a new project using the Cocoa Application template or manually add a target to your current project. You'll probably find it easier to start with a new project.
Add resource files to a command line tool
Add the file to the "Copy Files" section of your project's Build Phases:
Make sure to set Destination to "Resources", clear Subpath, and untick Copy only when installing.
Then whenever you build, Xcode will copy the file into your app's build directory, right next to the executable:
That's a screenshot of the ~/Library/Developer/Xcode/DerivedData/[your project]/Build/Products/Debug folder.
This method also works when you archive your app.
Note: if you want the file to be in some subfolder relative to the executable, e.g. res/images/, set the Subpath to that path.

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.

How can I include a txt file in an Xcode project?

I added a file "IntegerArray.txt" as follows, first I went to File -> Add file to "project name", I selected my file and it was copied into the root folder of my project, the same one that contains the .xcodeproj file. Then I clicked on my project's .xcodeproj file in Xcode, after which I went to Build Phases -> Copy Files -> "IntegerArray.txt", however when I build my project, the following code doesn't work
let bundle = NSBundle.mainBundle()
let path = bundle.pathForResource("IntegerArray", ofType: "txt")
println(path)
I expect to see the path to the file as output, but instead I see nil.
So I want to copy a file to my project in such a way that the above code works. How can I do this?
If I have a normal Cocoa Application, then when I add files they are automatically copied to the built program's bundle. However, with Command Line Tool's this doesn't seem to be the case, I'm starting to suspect a bug with Xcode.
If you don't have a Resources directory in your project, select your project:
Then from the File Menu select Add Files:
In the window that opens click on the "New Folder" button in the lower left hand corner of the window.
A small pop-up window will open; type Resources in that window for the folder name then click the "Create" button. You should now have a Resources folder in your project.
Then the way I do it is to use Finder to copy the file into the Resources Directory of my project.
After the file is in the Resources Directory (in Finder), back in Xcode select the Resources directory in your project:
and use the File-> Add Files menu selection again. You should see your file highlighted (affineOutput.txt in this case):
Double Click on it and it will become part of the bundle.
As Milliways says, then check the Build Phases in your project to be sure the file is in the Copy Bundle Resources. If it's somewhere else, just drag it into the Copy Bundle Resources.
If you include in the Resources Folder it should be included.
You may need to select the Project and Target.
In Build Phases check is there is entry under Copy Bundle Resources

How to have Xcode always copy files (even if they have not been detected as modified) when building?

I am developing an application which uses .js files stored in the Resources/javascript folder of my application bundle. In my Xcode 2.5 project I have created a folder reference (not a group) to my javascript folder, which automatically added the folder to the Copy Bundle Resources build phase.
The problem I have is when I modify my .js files, I need to clean my project then re-build it for the modified .js files to get copied into my application bundle when building. This is very time consuming since I re-build the whole project just to get an updated .js file in my app bundle.
Could someone tell me how to get Xcode to always copy specific files in the build phase?
Thanks in advance!
You could right- or control-click the file (in the project file list) and click "Touch" before building (manual) or add a script build phase to the target that calls "touch myfile.js" and place it before your Copy Files build phase (automatic).
Add a new Copy Files Build Task to your target.
Right Click (Control Click) on the target, Add -> New Build Phase -> New Copy Files Build Phase.
In the Dialog select the destination that you want the files to be copied.
This will create the phase under the target. Drag the files you wish to copy to the phase.
There's an excellent walkthrough here of a build phase script which automates the 'touch' and saves the manual step of specifying each file you want included.

Resources