Building a macOS commandline utility with a provisioning profile - objective-c

My goal is to build a macOS commandline binary with a Provisioning Profile (said profile is required, due to the use of Apple's new Endpoint Security Framework).
✅ I've created and installed the Provisioning Profile - and have no problem building and running macOS application version (Xcode auto populates the "Provisioning Profile", under "Signing and Capabilities", when the "Bundle Identifier" matches the one in the installed Provisioning Profile):
However, when attempting to build a commandline version, this option does not appear as Xcode believes "None [is] Required":
I've attempted to specify the Provisioning Profile anyways, via the project's "Build Settings" for the target:
❌ But building fails with:
processMonitor does not support provisioning profiles. processMonitor does not support provisioning profiles, but provisioning profile Process Monitor has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor.
Note, the project's Provisioning Profile (under "Build Settings") is set to "Automatic"
❌ I've also had no luck via xcodebuild, which generates the same error:
$ xcodebuild -project "processMonitor.xcodeproj" -scheme processMonitor -configuration Release PROVISIONING_PROFILE_SPECIFIER="Process Monitor" DEVELOPEMENT_TEAM="<team id>"
Build settings from command line:
DEVELOPEMENT_TEAM = <team id>
PROVISIONING_PROFILE_SPECIFIER = Process Monitor
note: Using new build system
note: Planning build
note: Constructing build description
error: processMonitor does not support provisioning profiles. processMonitor does not support provisioning profiles, ...
So, the question is: is it possible to build a stand-alone macOS commandline binary that requires a Provisioning Profile? ...and if so, how?

FWIW, a stand-alone macOS command line binary can be code-signed and entitled using a provisioning profile if it is packaged in a traditional 'App Bundle' (.app) folder structure but not as a free standing single binary file.
There's an Endpoint Security example of this procedure posted in the Apple Developer forum: https://developer.apple.com/forums/thread/129596
The TLDR is to build a full-fledged '.app' project with Xcode including the proper entitlements, provisioning profile, code-signing configuration and then swap out the logic for the application's main executable (e.g. DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing) with the desired command line binary logic yielding a folder structure as follows (From Apple Developer Forum post above):
% find DaemonInAppsClothing.app
DaemonInAppsClothing.app
DaemonInAppsClothing.app/Contents
DaemonInAppsClothing.app/Contents/_CodeSignature
DaemonInAppsClothing.app/Contents/_CodeSignature/CodeResources
DaemonInAppsClothing.app/Contents/MacOS
DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing
DaemonInAppsClothing.app/Contents/embedded.provisionprofile
DaemonInAppsClothing.app/Contents/Info.plist
DaemonInAppsClothing.app/Contents/PkgInfo

Related

Build Fails with "Error:The process '/usr/bin/dotnet' failed with exit code 1" after adding "no-build:true" in the dotnet pack command

The CI pipeline works well if I remove the nobuild:true option from the DotNetCoreCLI#2 task to pack the Project (ie to create a NuGet package) but I am not able to understand what special except not building the project does the nobuild option brings.
I need not want to build the Project again as the Previous task have already build the Project and locked the Assembly version of DLLs generated. I want to use the same build to create the NuGet package and to do the same I need to pass the NoBuild option but doing the same breaks the pipeline.
The pipeline gives the error that the DLLs to be packed are not present at the specified location but I tried to look at the location and I could find the DLLs.One thing that confuses me is that though I have given nobuild to be true but still the tasks shows as Building the Project.
- task: DotNetCoreCLI#2
displayName: ".NET pack"
inputs:
command: pack
packagesToPack: ${{ parameters.packagesToPack }}
nobuild: true
versioningScheme: byEnvVar
versionEnvVar: CI_Version
packDirectory: $(build.artifactStagingDirectory)\${{ parameters.packTo }}
verbosityPack: 'Normal'
Its also important to note that the same thing( nobuild:true) works on Windows Agent but it fails on Ubuntu Agent.
PS: It could be a case where windows has upgraded the agent and has caused the issue. I searched over the issue and found that one has to lock the .net SDK in the build pipeline
Thanks for the other answers that may be related to the issue but things were already taken care.
The issue was only on the Linux Environment because of an issue in .NET SDK. Refer here
The error(DLLs could not be found in the path specified ) that was being generated was correct in somehow but also it was misleading. The DLLs were being generated in Release folder at the build stage and when I was packing the DLLs they were being searched in release folder.
Though Release and release remains the same in Windows Environment but Ubuntu being case sensitive generates the Error.
The SDK implementation of .Net Core missed the IgnoreCase in the Regex option and that caused the build to break on switchin to a Linux Agent.
DotnetBuild:
Dotnet Pack:
Solution: Define the folder where to generate the DLLs in the .csproj and the automatically build and pack step would pick the DLLs from there.
For this error NU5026 ,it refers to the project being packed has not been built yet and hence cannot be packed. Please view this reference.
The file ''F:\project\bin\Debug\net461\project.exe' to be packed was not found on disk.
According to your description, you canceled the automatic build before pack. There's possibility that your build task and pack task did't run with same configuration. For example, In dotnet build task, the project is automatically built with Debug configuration, and in the pack task you set the configuration as Release.
In dotnet build task, the project is automatically built with Debug configuration.
In the dotnet pack task , the default Configuration to Package is Release
If you do not cancel the automatic build before pack, in the .net pack task the project is built in Release configuration.
So please check the log of your build task and pack task, make sure the dotnet build command and dotnet pack command use the same configuration.

Debugging QuickLook plug-in with 'bundle is damaged' error

We're adding a QuickLook plug-in to our project.
Everything is fine until macOS trying to invoke our plug-in, at which point we're getting the beloved The bundle couldn’t be loaded because it is damaged or missing necessary resources error.
We've checked with otool -L on the plug-in's binary that all dependencies are in place, however as soon as the OS is asking our plug-in for a preview for the file type supported by us we get:
22/04/17 12:03:05,716 quicklookd[55323]:
[QL] Can't load plug-in at file:///Users/myname/Library/Developer/Xcode/DerivedData/The_Project-gpihzjouhxvifqcslmywktktizer/Build/Products/Debug/MyApp.app/Contents/Library/QuickLook/SomeQuickLookPlugIn.qlgenerator/:
The bundle “SomeQuickLookPlugIn” couldn’t be loaded because it is damaged or missing necessary resources.
The one thing we're not quite sure about is the dependency to our internal frameworks.
We've set up the plug-in similar to our main app, i.e. the private framework dependency resolves to:
#executable_path/../Frameworks/MyFW.framework/Versions/A/MyFW (compatibility version 1.0.0, current version 1.0.0)
..which would work OK if #executable_path were either the main app's binary or the plug-in's main binary as we copied the frameworks in both places in the bundle.
Any thoughts?
Ideally we would like the OS to tell us which dependency it failed to resolve -
is there any debug flag that can be set..?
As per https://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html and http://www.dribin.org/dave/blog/archives/2009/11/15/rpath/ you should
set the Installation Directory for your referenced framework(s) to #rpath
in the app set Runtime Search Paths to #loader_path/../Frameworks
and in the QuickLook plug-in set Runtime Search Paths to #loader_path/../../../../../Frameworks as suggested by catlan -
that way you don't need to duplicate referenced frameworks inside the QuickLook plug-in
Compile, run, and everything should just work if everything else is set up correctly.
In addition you might want to check the code-signing settings in your plug-in to make sure there's no problems there.
One thing you can do is remove (or turn-off) code signing from your app and then see if it will load the plug-in…
To check if code-signing is the problem you can turn it off temporarily for your app using the Terminal to codesign --remove-signature YourApp.app and see if it works..
Run Search Paths should be #loader_path/../../../../../Frameworks because it is installed into Main.app/Contents/Library/QuickLook/QuickLookPlugin.qlgenerator/Contents/Mac/QuickLookPlugin, so we need to go five folders down from the #loader_path to find the frameworks folder.

Is there any way to change the dynamic library search path in Xcode

Below is my scenario,
In my Application i had to make use of libopus library , i downloaded and install, compile --> install procedure is normal as its for any other open source library,
I linked libopus.a with my application, the way i did is , by default it will get installed in /usr/local/lib, so i drag from there and add it to my application,
Worked fine and no error on my machine,
On Another machine, i was expecting it to be run smoothly as i included this library statically, but its throwing error as
dyld: Library not loaded: /usr/local/lib/libopus.0.dylib
so i concluded, libopus.a somehow including libopus.0.dylib also dynamically,
Now i am able ot add a copy phase in my build setting , so it will get copied in ../Framework folder
if i do otool -L libpus.a then it shows following result
otool -L /usr/local/lib/libopus.a
Archive : /usr/local/lib/libopus.a
/usr/local/lib/libopus.a(bands.o):
/usr/local/lib/libopus.a(celt.o):
/usr/local/lib/libopus.a(cwrs.o):
/usr/local/lib/libopus.a(entcode.o):
/usr/local/lib/libopus.a(entdec.o):
/usr/local/lib/libopus.a(entenc.o):
/usr/local/lib/libopus.a(repacketizer.o):
It doesn't show as its depend upon the dylib library
Now my Question is
How to tell Application to look into this path first
I tried following option,
install_name_tool but it seems it will work on other machine , so the user need to run this script NOT DEVELOPER,
trying to set the some option in the xcode to set the RUNTIME Search path to locate that particular dylib but not getting succeed so far
install_name_tool is run by the developer during the build process, not by the user.
If you're building the library, you should use libtool(1) with the option -install_name #rpath; otherwise, you can use install_name_tool(1) with -id #rpath to do the same thing on the dylib. Then, when you're building your application, set the "Runpath search paths" to the path where you will install the library.
Apple has some good documentation on this in their Mach-O Programming Topics and Dynamic Library Programming Topics.

How can I use xcodebuild in command line?

I'm a newbie to xcode.
I'm using xcode 4.3 with lion. I want to use xcodebuild in command line, but it report "no such file". I searched it with Finder, but no result.
What is this file's path? Does it exist in the Xcode.app?
Can I search files in a .app package?
Additional info:
When I typed "which xcodebuild", it return /usr/bin/xcodebuild. Enter this folder, and type xocdebuild, it still return Error:
Can't run /Applications/usr/bin/xcodebuild (no such file).
/usr/bin/xcodebuild only calls the xcodebuild command from the developer tools directory given by xcode-select. To find out the current developer tools directory as given by xcode-select run
xcode-select -print-path
I fixed the issue by changing that path executing
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Which is where my developer tools are. You should change /Applications/Xcode.app to wherever your Xcode application is.
The installer put mine in
/usr/bin/xcodebuild
You can also find it in the application bundle:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
CHeck you have it installed. The command Line Tools for the latest XCodes are optional installs. You can install them from Xcode's preferences - Downloads Tab - Components.

How do I archive multiple targets with one action in xcode 4

I have a project with multiple targets that are all for different iOS Apps. For instance one traget for the lite version and another one for the pro version.
I want to build and archive all of my Apps at once. Currently I have a scheme for every target which I use to archive each app independently. But now I have to start the archiving, wait until it is done and then start the next one.
Is there a way to archive all apps with one single action in xcode 4 or using the command line?
The Build action in a scheme dictates what targets are built for what actions. Leave the defaults (so they'll all be built for the Archive action). When that scheme is active, it'll build all the requested targets just prior to archiving when you select Product -> Archive.
You could create a new scheme called "All", edit it, then in its Build action, add all targets you want to archive. Then just select that scheme and ask it to archive.
Alternatively, add all targets to your existing scheme and uncheck unwanted actions for which it should build those extra targets, leaving only Archive.
You can use xcodebuild from the commandline
e.x.
xcodebuild -configuration Release -project MyProject -scheme MyProjectScheme clean build
Also you can use xcrun to build an ipa from the commandline as well, see:
https://stackoverflow.com/a/4198166/618419