title: Obtaining Library Version Number in Xcode workspace
body: <h2>Problem</h2>
  <p>I'm working on an Xcode project that's meant to be built into a library and included in other projects, either as a CocoaPod or in a workspace. I'm using agvtool to set the bundle and marketing versions.  I wanted to add a simple method for reading the version of the library as part of the API, and it's turned into a much more complicated thing than I anticipated. I had initially implemented my versionString method like this:</p>
  <pre><code>+ (NSString *)versionString {
    return [NSString stringWithFormat:@&quot;%@.%@&quot;, [[[NSBundle mainBundle] infoDictionary] objectForKey:@&quot;CFBundleShortVersionString&quot;], [[[NSBundle mainBundle] infoDictionary] objectForKey:@&quot;CFBundleVersion&quot;]];
  }
  </code></pre>
  <p>However, when the library is included in a workspace, <code>CFBundleShortVersionString</code> and <code>CFBundleVersion</code> get their values from the workspace, <strong>not</strong> from the library! So, if the library is marketing version 1.2 and the bundle version is 3, but it is included in a workspace that is marketing version 2.0 and bundle version 130, this method would return <code>2.0.130</code> instead of <code>1.2.3</code>.</p>
  <p>Does anyone know of a way that I can get access to the library's <code>CFBundleShortVersionString</code> instead of the workspace's?</p>
  <h2>Additional Info</h2>
  <p>I started digging into some of the more obscure aspects of <code>agvtool</code>, and I've discovered a reliable way to get access to the bundle version, but what I would really prefer is the marketing version, as that's what I would use to indicate API compatibility.</p>
  <p><code>agvtool</code> will set the <code>Current Project Version</code> property in your build settings, so if you set <code>Versioning System</code> to <code>Apple Generic</code>, Xcode will generate a .c file with some global constants for you as part of the build process. All you have to do to gain access to those values is expose them in your own header, like this:</p>
  <pre><code>extern const unsigned char {PRODUCT NAME}VersionString[];
  extern const double {PRODUCT NAME}VersionNumber;
  </code></pre>
  <p>When I saw this, I thought for sure I was on the right track. VersionNumber is indeed 3.0, but VersionString is <code>@(#)PROGRAM:{PRODUCT NAME}  PROJECT:{PRODUCT NAME}-3</code>.</p>
  <p>It seems like I might be able to get what I want by setting the <code>Generated Versioning Variables</code> parameter in the build settings, but I'm also getting the suspicion that I started in the wrong direction and I'm only getting further off track.</p>
  <p>Any help would be greatly appreciated.</p>