How to add framework reference to a framework from a different project - xcodeproj

I using Cocoapods/xcodeproj gem to generate my Xcode projects, for a framework in the same project I can do
common = project.targets.find { |t| t.name == "TestCommon" }
target.frameworks_build_phases.add_file_reference(common.product_reference)
But this doesn't work if framework and the target are from separate projects but in the same workspace.

Related

How to tell entitiy framework that my db context class is avaiable in core project to run the migration in diffrent project?

Dear Developers,
I am new to EF.
I have this project srtucture.
+ HrSoultion
+ <Application> // namespace project
- api // this is the mvc core project
+ <Core> // namespace project
- Entity// this is the project where I defined the models and db context class
Now I am confused where to run the add Add-Migration HrSoultion.Core.HrSoultionContext
Thanks ?
Option 1: Use command line
dotnet ef migrations add Init
Option 2: Select appropriate project before you run Add-Migration command in Package Manager Console. E.g.

Gradle DSL - Eclipse Equivalent for IDEA Module Property

Good localtime,
I am in the process of updating legacy (4.8.1) Gradle build files for a big-McLarge-huge, multimodule project. We utilize an intellij.gradle file which has the following line (marked by comment):
idea {
module {
inheritOutputDirs = true // <-- HOW DO I DO THIS
downloadJavadoc = true
downloadSources = true
}
workspace.iws.withXml { provider ->
def node = provider.asNode()
def dynamicClasspath = node.component.find { it."#name" == "dynamic.classpath" }
if (dynamicClasspath != null) {
dynamicClasspath."#value" = "true"
}
}
From the 4.8.1 DSL docs:
If true, output directories for this module will be located below the
output directory for the project; otherwise, they will be set to the
directories specified by IdeaModule.getOutputDir() and
IdeaModule.getTestOutputDir().
Any ideas on what the Eclipse DSL equivalent of inheritOutputDirs? Should this be handled using the eclipseClasspath API? Right now everything is building fine, but the Eclipse Java builder is is flagging things.
References:
https://docs.gradle.org/4.8.1/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
https://docs.gradle.org/4.8.1/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html
Usually this would have been picked up through sourceSets but I can't see what your project looks like...
If your subproject uses Gradle to generate sources into /build/cxf/generated-sources directory, then you can tell Eclipse via Gradle DSL to include that as a source folder like this:
plugins { id 'eclipse' }
eclipse.classpath.file.whenMerged {
// this is the brute-force approach; there is likely a better way to add a source folder
entries << new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/cxf/generated-sources', null)
}
Once this is run (via gradle eclipseClasspath) you should see a build/cxf/generated-sources folder under your project node in the Package Explorer or Project Explorer. Sort of like this:
NOTE: This is untested because I don not have a sample project to work with.
There is more discussion here: How to add gradle generated source folder to Eclipse project?

Exporting Package.swift for Swift Package Manager from existing Xcode project

I'm working with Xcode 11.3 on macOS Catalina 10.15.6.
I have an existing Xcode project which builds an app for iOS. I am interested in reusing some of the classes in an interactive session with the swift command line interpreter. The classes I want to work with are Core Data classes which are autogenerated from an Xcode data model and also some classes I've written which work with the Core Data classes. The app has UI screens and makes use of UIKit but I'm not trying to use any of those classes; I'm hoping that I can either compile those classes and then not refer to them, or somehow tell Swift Package Manager to ignore those classes altogether.
What I think I would like to do is to export a Package.swift for the existing Xcode project, such that swift build at the command line would be able to compile all of the project classes, or, failing that, at least the non-UI classes, and then swift run --repl would be able to load the classes via import.
I see a menu item in Xcode to create a new Swift package, but not to export an existing project. Is there a way to export an existing project?
There are no a menu command or utility to convert application to a static library, dynamic framework or swift package since they are different types of projects with different settings etc.
If you want to export a part of your project as a swift package you should make next steps manually:
1. Create Package.swift file in the root of your project
import PackageDescription
let package = Package(
name: “MyLib”,
products: [
.library(name: "MyLib", targets: ["MyLib"])
],
targets: [
.target(name: "MyLib"),
],
...
)
2. Make folder with subfolder ./Sources/MyLib under the projects’s root.
By default swift package structure requires to put all your sources files under Sources/LibraryName folder but you can change it below.
NOTE: you can simplify first two steps by using swift package init and it creates Package.swift, Sources and Test folders etc.
3. Include source files
a) Move the needed files to share from their current locations to MyLib folder.
For instance:
./Classes/MyEntity.swift -> ./Sources/MyLib/MyEntity.swift
Also you have to update locations of the moved files in your Xcode project to leave it compilable.
b) Use path, sources and exclude to point needed source files to your package from their current locations:
.target(name: "MyLib", path: "Classes"),
NOTE: Don't forget to make your classes public to access to them after import your package:
public class MyEntity {
...
}
After all you will have two working projects - old XCode's one and new Swift package.
4. REPL
Now you can use command line interpreter with your swift package:
swift run --repl
import MyLib
let entity = MyEntity()
...

.NET Core 2.1 version error with Cake Build 4.0 NuGetRestore and MSBuild actions

Cake Build 4.0.0 runs NuGetRestore and MSBuild methods by executes MSBuild CLI command. From my understanding, Cake downloads certain version of MSBuild. In my solution, it is mostly .NET Framework, but our testing project is targeting .NET Core 2.1 (we will eventually move our whole project to .NET Core 2.1+ but cannot right now). I am experiencing the following error:
C:\git\OurProduct\PPUXL\tools\.dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\git\OurProduct\PPUXL\src\Portals\Core\OurProduct.Tests\OurProduct.Tests.csproj]
So normally I would download a new SDK, but we are going to run the script on Azure DevOps on a build agent and the SDKs are not part of our workstation but are downloaded and compiled by Cake via the Powershell script we run.
Here is the code the causes the error:
Task("Restore")
.Does(() =>
{
//We need to change this code if we switch from .NET Framework to .NET Core for this project.
NuGetRestore(
solution,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
NuGetRestore(
project,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
}
});
Task("Build")
.Does(() =>
{
MSBuild(
SAMLProject,
new MSBuildSettings()
.SetConfiguration(configuration)
.WithProperty("DeployOnBuild", "true")
.WithProperty("PublishProfile", configuration)
.WithProperty("publishUrl", SAMLDeployDirectory)
.WithProperty("WebPublishMethod", "FileSystem")
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
if(!project.FullPath.Contains("Tests") && !project.FullPath.Contains("SAML"))
{
MSBuild(
project,
new MSBuildSettings()
.SetConfiguration(configuration)
);
}
}
MSBuild(
testProject,
new MSBuildSettings()
.SetConfiguration(configuration)
);
});
I can get prevent the error by doing this:
Task("Restore")
.Does(() =>
{
//We need to change this code if we switch from .NET Framework to .NET Core for this project.
NuGetRestore(
solution,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
if(!project.FullPath.Contains("Tests") && !project.FullPath.Contains("SAML"))
{
NuGetRestore(
project,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
}
}
});
Task("Build")
.Does(() =>
{
MSBuild(
SAMLProject,
new MSBuildSettings()
.SetConfiguration(configuration)
.WithProperty("DeployOnBuild", "true")
.WithProperty("PublishProfile", configuration)
.WithProperty("publishUrl", SAMLDeployDirectory)
.WithProperty("WebPublishMethod", "FileSystem")
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
if(!project.FullPath.Contains("Tests") && !project.FullPath.Contains("SAML"))
{
MSBuild(
project,
new MSBuildSettings()
.SetConfiguration(configuration)
);
}
}
MSBuild(
testProject,
new MSBuildSettings()
.SetConfiguration(configuration)
);
});
How can run the build methods to target the correct .NET Core libraries using Cake? I want the build to all happen within my Powershell script and my Cake script with no environmental influence. Thanks in advance.
Cake doesn't download any tools automatically, it does resolve tools automatically though.
The error would suggest that the machine the build is running on lacks an .NET Core SDK that can build .NET Core 2.1 apps.
You can download an install .NET Core SDK from https://dotnet.microsoft.com/download/dotnet-core/2.1
For Azure DevOps you can use the .NET Core Tool Installer task to ensure
If you want to contain your tools with in repository and not install anything into i.e. program files, then installing SDK using a PowerShell/Bash boostrapper is a way to ensure everyone's gets and uses the same SDK without affecting the rest of the system.
Microsoft provides scripts for obtaining the SDK at
https://dot.net/v1/dotnet-install.ps1
https://dot.net/v1/dotnet-install.sh
Example usage:
dotnet-install.ps1 -Channel 'LTS' -Version '2.1.603' -InstallDir '.\dotnet';
Cake project itself uses this method in it's build.ps1, downloading the SDK version it needs if it's not available on the machine.
If you also want to ensure you're using the downloaded SDK to build your projects, then you can switch from NuGetRestore/MSBuild aliases to
DotNetCoreRestore
DotNetCoreBuild
These aliases will invoke the .NET Core CLI, and if the downloaded .NET COre CLI is first in path or specified on the .NET Core aliases settings ToolPath property, then it'll be the one used. .NET Core SDK can build both .NET Core and .NET Framework projects. I.e. the Cake project achieves this in its in it's build.ps1 by adding the dotnet folder first in path environment variable.

How to allow / workaround nested composite Gradle builds

I'm running into the same issue as reported here:
I have a Java project A which depends on project B (module), and
project B dependes on project C (another module). For project A I
would like to setup "includeBuild ../projectB" and for project B I
would like too setup "includeBuild ../projectC" so that I could
develop everything in Eclipse + Buildship 2.0 without the need to run
Gradle for every small change in each of the projecta A, B and C.
But if I setup this I get: "Included build '%s' cannot have included
builds.".
Expected Behavior
Recursive "includeBuild" would recursively include dependent projects.
Current Behavior
I get "Included build '%s' cannot have included builds.".
Your Environment
Gradle 3.5, Buildship 2.0, Eclipse 3.6
How can I resolve / work around this issue? In my instance, I have utility project that includes email functionality (using JavaMail). The email functionality is needed in the data project and a UI project. The UI project also depends on the data project.
Adding another answer for a different approach...
Each settings.gradle could add a check to before includeBuild to see if it's already inside a composite. If it's already inside a composite, it doesn't includeBuild.
See here for extra info on the composite check
Eg
project2/settings.gradle
boolean inComposite = gradle.parent != null
if (!inComposite) {
includeBuild '../project1'
}
project3/settings.gradle
boolean inComposite = gradle.parent != null
if (!inComposite) {
includeBuild '../project1'
includeBuild '../project2'
}
project4/settings.gradle
boolean inComposite = gradle.parent != null
if (!inComposite) {
includeBuild '../project1'
includeBuild '../project2'
includeBuild '../project3'
}
etc etc
Using this approach you could run gradle from wherever you like and it should behave as expected (ie substitute dependencies with local projects)
Have you considered
Ensuring that none of the individual builds are composite builds
Having an "uber" build which is a composite of everything
Note that the settings.gradle is itself a groovy script, so you could create a dynamic composite, eg all sub-folders with a build.gradle under a parent.
uber/settings.gradle
new File("c:/someFolder").listFiles().each { File f ->
if (f.directory && new File(f, 'build.gradle').exists()) {
includeBuild f
}
}
Eg
c:/someFolder/project1/build.gradle
c:/someFolder/project1/src/main/java/**/*.java
c:/someFolder/project2/build.gradle
c:/someFolder/project2/src/main/java/**/*.java
c:/uber/settings.gradle (as above)