Skip to content

Commit 1d4f8ba

Browse files
committed
Merge branch 'cherry-pick-b92c2f6b' into 'main'
Exposes CopyLocal/Private setting for dotnet project reference and change DependencySetting.Default value See merge request Sharpmake/sharpmake!625
2 parents 05cb954 + 61cf1ca commit 1d4f8ba

File tree

17 files changed

+176
-13
lines changed

17 files changed

+176
-13
lines changed

Sharpmake.Generators/VisualStudio/Csproj.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ List<string> skipFiles
14861486
// FIXME : MsBuild does not seem to properly detect ReferenceOutputAssembly setting.
14871487
// It may try to recompile the project if the output file of the dependency is missing.
14881488
// To counter this, the CopyLocal field is forced to false for build-only dependencies.
1489-
bool isPrivate = project.DependenciesCopyLocal.HasFlag(Project.DependenciesCopyLocalTypes.ProjectReferences) && dependency.ReferenceOutputAssembly != false;
1489+
bool isPrivate = dependency.CopyLocal && project.DependenciesCopyLocal.HasFlag(Project.DependenciesCopyLocalTypes.ProjectReferences) && dependency.ReferenceOutputAssembly != false;
14901490

14911491
string includeOutputGroupsInVsix = null;
14921492
if (isPrivate && project.ProjectTypeGuids == CSharpProjectType.Vsix)
@@ -1547,7 +1547,7 @@ List<string> skipFiles
15471547
Include = $"{dependency.Configuration.AssemblyName}{(isMultiFramework ? "-" + GetTargetFrameworksString(targetFramework) : "")}",
15481548
SpecificVersion = false,
15491549
HintPath = Util.PathGetRelative(_projectPathCapitalized, dllPath),
1550-
Private = project.DependenciesCopyLocal.HasFlag(Project.DependenciesCopyLocalTypes.ExternalReferences),
1550+
Private = dependency.CopyLocal && project.DependenciesCopyLocal.HasFlag(Project.DependenciesCopyLocalTypes.ExternalReferences),
15511551
};
15521552
itemGroups.AddReference(targetFramework, referencesByPath);
15531553
}

Sharpmake.Generators/VisualStudio/Vcxproj.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ private void GenerateProjectReferences(
988988
// Write dotNet dependencies references
989989
{
990990
// The behavior should be the same than for csproj...
991-
string projectDependenciesCopyLocal = firstConf.Project.DependenciesCopyLocal.HasFlag(Project.DependenciesCopyLocalTypes.ProjectReferences).ToString().ToLower();
991+
bool isDependenciesProjectReferences = firstConf.Project.DependenciesCopyLocal.HasFlag(Project.DependenciesCopyLocalTypes.ProjectReferences);
992992

993993
Options.ExplicitOptions options = new Options.ExplicitOptions();
994994
options["CopyLocalSatelliteAssemblies"] = FileGeneratorUtilities.RemoveLineTag;
@@ -1040,7 +1040,7 @@ private void GenerateProjectReferences(
10401040
using (projectFilesWriter.Declare("include", include))
10411041
using (projectFilesWriter.Declare("projectGUID", dependency.ProjectGuid ?? FileGeneratorUtilities.RemoveLineTag))
10421042
using (projectFilesWriter.Declare("projectRefName", dependency.ProjectName))
1043-
using (projectFilesWriter.Declare("private", projectDependenciesCopyLocal))
1043+
using (projectFilesWriter.Declare("private", (dotNetDependency.CopyLocal && isDependenciesProjectReferences).ToString().ToLower()))
10441044
using (projectFilesWriter.Declare("options", options))
10451045
{
10461046
projectFilesWriter.Write(Template.Project.ProjectReference);

Sharpmake.UnitTests/CSharpDependencyPropagationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ public CSharpProjectDependencySwappedToDLL() { }
538538
[Configure()]
539539
public void ConfigureAll(Configuration conf, Target target)
540540
{
541-
conf.AddPublicDependency<CSharpInheritOnePublicDependencyProject>(target, DependencySetting.DependOnAssemblyOutput);
541+
conf.AddPublicDependency<CSharpInheritOnePublicDependencyProject>(target, DependencySetting.Default | DependencySetting.DependOnAssemblyOutput);
542542
conf.AddPublicDependency<CSharpProjectB>(target);
543543
}
544544
}

Sharpmake/DotNetDependency.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class DotNetDependency
88
public Project.Configuration Configuration { get; }
99
public bool? ReferenceOutputAssembly { get; set; }
1010
public bool ReferenceSwappedWithOutputAssembly { get; set; } = false;
11+
public bool CopyLocal { get; set; } = true;
1112

1213
public DotNetDependency(Project.Configuration configuration)
1314
{

Sharpmake/Project.Configuration.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,25 @@ public enum DependencySetting
6969
/// </summary>
7070
NoProjectReference = 1 << 8,
7171

72+
/// <summary>
73+
/// Indicates if the reference dll should be copied to the output folder. Represents the Private option of project reference.
74+
/// Valid only for C# projects.
75+
/// </summary>
76+
/// <remarks>
77+
/// Private: Specifies whether the reference should be copied to the output folder.
78+
/// This attribute matches the Copy Local property of the reference that's in the Visual Studio IDE.
79+
/// </remarks>
80+
CopyLocal = 1 << 9,
81+
7282
/// <summary>
7383
/// Specifies that the dependent project inherits the dependency's library files, library
7484
/// paths, include paths and defined symbols.
7585
/// </summary>
7686
Default = LibraryFiles |
7787
LibraryPaths |
7888
IncludePaths |
79-
Defines,
89+
Defines |
90+
CopyLocal,
8091

8192
/// <summary>
8293
/// Specifies that the dependent project inherits the dependency's include paths and
@@ -89,6 +100,12 @@ public enum DependencySetting
89100
DefaultForceUsing = ForceUsingAssembly
90101
| IncludePaths
91102
| Defines,
103+
104+
/// <summary>
105+
/// Indicates that the dependency use the default setting while not copying the dll
106+
/// to the current project output path (Private = false). Only use with C# dependency.
107+
/// </summary>
108+
DefaultWithoutCopy = Default & ~CopyLocal
92109
}
93110

94111
/// <summary>
@@ -3875,7 +3892,8 @@ IConfigurationTasks GetConfigurationTasks(Platform platform)
38753892
var dotNetDependency = new DotNetDependency(dependency)
38763893
{
38773894
ReferenceOutputAssembly = referenceOutputAssembly,
3878-
ReferenceSwappedWithOutputAssembly = isDotnetReferenceSwappedWithOutputAssembly
3895+
ReferenceSwappedWithOutputAssembly = isDotnetReferenceSwappedWithOutputAssembly,
3896+
CopyLocal = visitedNode._dependencySetting.HasFlag(DependencySetting.CopyLocal)
38793897
};
38803898

38813899
if (isDotnetReferenceSwappedWithOutputAssembly)

samples/CPPCLI/projects.sharpmake.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public override void ConfigureAll(Configuration conf, Target target)
7777
public class OtherCSharpProj : CommonCSharpProject
7878
{
7979
public OtherCSharpProj() { }
80+
81+
public override void ConfigureAll(Configuration conf, Target target)
82+
{
83+
base.ConfigureAll(conf, target);
84+
conf.Output = Configuration.OutputType.DotNetClassLibrary;
85+
}
8086
}
8187

8288
[Sharpmake.Generate]
@@ -103,7 +109,7 @@ public override void ConfigureAll(Configuration conf, Target target)
103109
"System.Xml"
104110
);
105111

106-
conf.AddPrivateDependency<OtherCSharpProj>(target);
112+
conf.AddPrivateDependency<OtherCSharpProj>(target, DependencySetting.DefaultWithoutCopy);
107113
conf.AddPrivateDependency<CSharpProjBuildOrderDependency>(target, DependencySetting.OnlyBuildOrder);
108114
conf.AddPrivateDependency<TheEmptyCPPProject>(target);
109115

samples/CPPCLI/reference/projects/clrcppproj.vs2019.v4_6_2.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@
252252
<ProjectReference Include="CSharpProjBuildOrderDependency.vs2019.v4_6_2.csproj">
253253
<Project>{20203136-87D4-8326-EEDC-676EFF6A2BE4}</Project>
254254
<Name>CSharpProjBuildOrderDependency</Name>
255-
<Private>true</Private>
255+
<Private>false</Private>
256256
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
257257
<LinkLibraryDependencies>false</LinkLibraryDependencies>
258258
</ProjectReference>
259259
<ProjectReference Include="OtherCSharpProj.vs2019.v4_6_2.csproj">
260260
<Project>{0F0B5234-FCD8-1E42-5072-C6FFF3870C9B}</Project>
261261
<Name>OtherCSharpProj</Name>
262-
<Private>true</Private>
262+
<Private>false</Private>
263263
</ProjectReference>
264264
<ProjectReference Include="theemptycppproject.vs2019.v4_6_2.vcxproj">
265265
<Project>{0BCBC674-3C8D-5295-B9C2-7CDC47ED8A55}</Project>

samples/CPPCLI/reference/projects/clrcppproj.vs2022.v4_7_2.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@
252252
<ProjectReference Include="CSharpProjBuildOrderDependency.vs2022.v4_7_2.csproj">
253253
<Project>{FCE70296-BFEE-87F2-6BB4-6EDA713DA129}</Project>
254254
<Name>CSharpProjBuildOrderDependency</Name>
255-
<Private>true</Private>
255+
<Private>false</Private>
256256
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
257257
<LinkLibraryDependencies>false</LinkLibraryDependencies>
258258
</ProjectReference>
259259
<ProjectReference Include="OtherCSharpProj.vs2022.v4_7_2.csproj">
260260
<Project>{C67510CE-FE51-F409-686E-F1DFBD047DAA}</Project>
261261
<Name>OtherCSharpProj</Name>
262-
<Private>true</Private>
262+
<Private>false</Private>
263263
</ProjectReference>
264264
<ProjectReference Include="theemptycppproject.vs2022.v4_7_2.vcxproj">
265265
<Project>{73752EE3-3CA0-703C-E295-427A8187946C}</Project>

samples/CSharpHelloWorld/HelloWorld.sharpmake.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ public static Target[] GetDefaultTargets()
3030
}
3131
}
3232

33+
[Sharpmake.Generate]
34+
public class HelloWorldReference : CSharpProject
35+
{
36+
public HelloWorldReference()
37+
{
38+
AddTargets(TargetTypes.GetDefaultTargets());
39+
RootPath = @"[project.SharpmakeCsPath]\projects\[project.Name]";
40+
SourceRootPath = @"[project.SharpmakeCsPath]\codebase\[project.Name]";
41+
}
42+
43+
[Configure()]
44+
public virtual void ConfigureAll(Configuration conf, Target target)
45+
{
46+
conf.ProjectFileName = "[project.Name].[target.DevEnv].[target.Framework]";
47+
conf.ProjectPath = @"[project.RootPath]";
48+
conf.Options.Add(Sharpmake.Options.CSharp.TreatWarningsAsErrors.Enabled);
49+
conf.Output = Configuration.OutputType.DotNetClassLibrary;
50+
}
51+
}
52+
3353
[Sharpmake.Generate]
3454
public class HelloWorld : CSharpProject
3555
{
@@ -53,6 +73,7 @@ public virtual void ConfigureAll(Configuration conf, Target target)
5373
conf.CustomProperties.Add("CustomOptimizationProperty", $"Custom-{target.Optimization}");
5474

5575
conf.Options.Add(Sharpmake.Options.CSharp.TreatWarningsAsErrors.Enabled);
76+
conf.AddPublicDependency<HelloWorldReference>(target, DependencySetting.DefaultWithoutCopy);
5677
}
5778
}
5879

samples/CSharpHelloWorld/codebase/HelloWorldReference/HelloWorldReference.cs

Whitespace-only changes.

0 commit comments

Comments
 (0)