Skip to content

Commit

Permalink
fix #2520 new option to control interproject references version const…
Browse files Browse the repository at this point in the history
…raints
  • Loading branch information
lexarchik committed Jan 29, 2019
1 parent 2065231 commit d9866d5
Show file tree
Hide file tree
Showing 34 changed files with 414 additions and 15 deletions.
9 changes: 6 additions & 3 deletions docs/content/commands/pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ paket pack nugets --symbols
### Including referenced projects

Paket automatically replaces inter-project dependencies with NuGet dependencies
if the dependency has it's own [`paket.template`][templatefile]. In addition to
this the parameter `--include-referenced-projects` instructs Paket to add
project output to the package for inter-project dependencies that don't have a
if the dependency has its own [`paket.template`][templatefile]. Version constraints
for these dependencies can be controlled with the `--interproject-references`
parameter or the `interproject-references` option in [`paket.template`][templatefile].

In addition to this the parameter `--include-referenced-projects` instructs Paket to
add project output to the package for inter-project dependencies that don't have a
[`paket.template` file][templatefile].

1. It recursively iterates referenced projects and adds their project output to
Expand Down
25 changes: 25 additions & 0 deletions docs/content/template-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,31 @@ referenced projects into the package.
include-referenced-projects true
```

If the referenced project has its own template file then it will be added to the package
as NuGet dependency. You can control the version constraint for such dependencies with
the `interproject-references` option.
There are several possible values for this options. Consider them with an example.

`ProjectA` references `ProjectB`. Both projects have template files.
`ProjectB`'s version is `1.2.3`.

(The first column is a line from `ProjectA`'s template file,
the second column is a version constraint for the `ProjectB` dependency in `ProjectA.nupkg`.)

|||
| --- | --- |
| `interproject-references min` | `1.2.3` |
| `interproject-references fix` | `[1.2.3]` |
| `interproject-references keep-major` | `[1.2.3,2.0.0)` |
| `interproject-references keep-minor` | `[1.2.3,1.3.0)` |
| `interproject-references keep-patch` | `[1.2.3,1.2.4)` |
|||

The default value is `interproject-references min`.

You can override the template file option with the CLI parameter
`--interproject-references` which supports the same values.

#### References

A references block looks like this:
Expand Down
46 changes: 46 additions & 0 deletions integrationtests/Paket.IntegrationTests/PackSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,52 @@ let ``#1848 include-referenced-projects with non-packed project dependencies`` (

CleanDir rootPath

[<Test>]
let ``#2520 interproject-references parameter overide --pin-project-references`` () =
let scenario = "i002520-interproject-references-constraint"
let rootPath = scenarioTempPath scenario
let outPath = Path.Combine(rootPath, "out")
let package = Path.Combine(outPath, "A.1.0.0.nupkg")

paket ("pack --pin-project-references \"" + outPath + "\"") scenario |> ignore
ZipFile.ExtractToDirectory(package, outPath)

let nuspec = NuGetLocal.getNuSpecFromNupgk package
let dependency =
match nuspec.Dependencies.Value with
| [d] -> d
| _ -> failwith "single dependency expected"

let name, versionRequirement, _ = dependency

name |> shouldEqual (PackageName "B")
versionRequirement |> shouldEqual (VersionRequirement.Parse "[1.2.3,2.0.0)")

CleanDir rootPath

[<Test>]
let ``#2520 --interproject-references cli parameter overide interproject-references template file option`` () =
let scenario = "i002520-interproject-references-constraint"
let rootPath = scenarioTempPath scenario
let outPath = Path.Combine(rootPath, "out")
let package = Path.Combine(outPath, "A.1.0.0.nupkg")

paket ("pack --interproject-references keep-minor \"" + outPath + "\"") scenario |> ignore
ZipFile.ExtractToDirectory(package, outPath)

let nuspec = NuGetLocal.getNuSpecFromNupgk package
let dependency =
match nuspec.Dependencies.Value with
| [d] -> d
| _ -> failwith "single dependency expected"

let name, versionRequirement, _ = dependency

name |> shouldEqual (PackageName "B")
versionRequirement |> shouldEqual (VersionRequirement.Parse "[1.2.3,1.3.0)")

CleanDir rootPath

[<Test>]
let ``#2694 paket fixnuspec should not remove project references``() =
let project = "console"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\</OutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\B\B.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using B;

namespace A
{
public class ClassA
{
public ClassA()
{
var classB = new ClassB();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": "cfe1dc2a80602aef150a12815387068463a61a0d"
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"A/1.0.0": {
"dependencies": {
"B": "1.0.0",
"NETStandard.Library": "2.0.3"
},
"runtime": {
"A.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"B/1.0.0": {
"runtime": {
"B.dll": {}
}
}
}
},
"libraries": {
"A/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-WV99Ot6CEKqaIpW+ErjGXmbE3HX6bSoS7tqcOc7k1evmarPPENlLWDPlMx8lHXPltWXot0H45nhmSxtvy577Cg==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-s2Ei89UeBS1EmfipIvE+LAocCvKOWSVk+hMkPu8KXAYun9/5AS8m1u+7OIc9ZnAcM0aPGvNNcLSZpf0gCdaE9Q==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
},
"B/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type project
description test
authors test

interproject-references keep-major
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\</OutputPath>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace B
{
public class ClassB
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": "cfe1dc2a80602aef150a12815387068463a61a0d"
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"B/1.0.0": {
"dependencies": {
"NETStandard.Library": "2.0.3"
},
"runtime": {
"B.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
}
}
},
"libraries": {
"B/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-WV99Ot6CEKqaIpW+ErjGXmbE3HX6bSoS7tqcOc7k1evmarPPENlLWDPlMx8lHXPltWXot0H45nhmSxtvy577Cg==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-s2Ei89UeBS1EmfipIvE+LAocCvKOWSVk+hMkPu8KXAYun9/5AS8m1u+7OIc9ZnAcM0aPGvNNcLSZpf0gCdaE9Q==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type project
version 1.2.3
description test
authors test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A", "A\A.csproj", "{77D9C98B-BE20-4F46-96D3-A9813F8E9549}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "B", "B\B.csproj", "{64DD343C-CC8E-4FDF-8776-59E37EAF690D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{77D9C98B-BE20-4F46-96D3-A9813F8E9549}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77D9C98B-BE20-4F46-96D3-A9813F8E9549}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77D9C98B-BE20-4F46-96D3-A9813F8E9549}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77D9C98B-BE20-4F46-96D3-A9813F8E9549}.Release|Any CPU.Build.0 = Release|Any CPU
{64DD343C-CC8E-4FDF-8776-59E37EAF690D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64DD343C-CC8E-4FDF-8776-59E37EAF690D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64DD343C-CC8E-4FDF-8776-59E37EAF690D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64DD343C-CC8E-4FDF-8776-59E37EAF690D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source https://www.nuget.org/api/v2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/Paket.Core.preview3/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Compile Include="$(PaketCoreSourcesDir)\Versioning\SemVer.fs" />
<Compile Include="$(PaketCoreSourcesDir)\Versioning\VersionRange.fs" />
<Compile Include="$(PaketCoreSourcesDir)\Versioning\FrameworkHandling.fs" />
<Compile Include="$(PaketCoreSourcesDir)\Versioning\InterprojectReferencesConstraint.fs" />
<Compile Include="$(PaketCoreSourcesDir)\Versioning\PlatformMatching.fs" />
<Compile Include="$(PaketCoreSourcesDir)\Versioning\ConfigFile.fs" />
<Compile Include="$(PaketCoreSourcesDir)\Versioning\CredentialProviders.fs" />
Expand Down
23 changes: 18 additions & 5 deletions src/Paket.Core/Packaging/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,22 @@ let addFile (source : string) (target : string) (templateFile : TemplateFile) =
| IncompleteTemplate ->
failwith (sprintf "You should only try and add files to template files with complete metadata.%sFile: %s" Environment.NewLine templateFile.FileName)

let findDependencies (dependenciesFile : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies minimumFromLockFile pinProjectReferences (projectWithTemplates : Map<string, (Lazy<'TemplateFile>) * ProjectFile * bool>) includeReferencedProjects (version :SemVerInfo option) cache =
let findDependencies (dependenciesFile : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies minimumFromLockFile pinProjectReferences interprojectReferencesConstraint (projectWithTemplates : Map<string, (Lazy<'TemplateFile>) * ProjectFile * bool>) includeReferencedProjects (version :SemVerInfo option) cache =
let includeReferencedProjects = template.IncludeReferencedProjects || includeReferencedProjects
let targetDir =

let interprojectReferencesConstraint =
match interprojectReferencesConstraint with
| Some c -> c
| None ->
match template.InterprojectReferencesConstraint with
| Some c -> c
| None ->
if pinProjectReferences || lockDependencies then
InterprojectReferencesConstraint.Fix
else
InterprojectReferencesConstraint.Min

let targetDir =
match project.BuildOutputTargetFolder with
| Some x -> x
| None ->
Expand Down Expand Up @@ -293,7 +306,7 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
| CompleteTemplate(core, _) ->
match core.Version with
| Some v ->
let versionConstraint = if lockDependencies || pinProjectReferences then Specific v else Minimum v
let versionConstraint = interprojectReferencesConstraint.CreateVersionRequirements v
PackageName core.Id, VersionRequirement(versionConstraint, getPreReleaseStatus v)
| None -> failwithf "There was no version given for %s." evaluatedTemplate.FileName
| IncompleteTemplate ->
Expand Down Expand Up @@ -328,7 +341,7 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
let versionConstraint =
match core.Version with
| Some v ->
let vr = if lockDependencies || pinProjectReferences then Specific v else Minimum v
let vr = interprojectReferencesConstraint.CreateVersionRequirements v
VersionRequirement(vr, getPreReleaseStatus v)
| None -> VersionRequirement.AllReleases

Expand Down Expand Up @@ -393,7 +406,7 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
| None ->
match version with
| Some v ->
let vr = if lockDependencies || pinProjectReferences then Specific v else Minimum v
let vr = interprojectReferencesConstraint.CreateVersionRequirements v
np.Name,VersionRequirement(vr, getPreReleaseStatus v)
| None ->
if minimumFromLockFile then
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/Packaging/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ let private convertToSymbols (projectFile:ProjectFile) includeReferencedProjects
let augmentedFiles = optional.Files |> List.append sourceFiles
{ templateFile with Contents = ProjectInfo({ core with Symbols = true }, { optional with Files = augmentedFiles }) }

let Pack(workingDir,dependenciesFile : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, minimumFromLockFile, pinProjectReferences, symbols, includeReferencedProjects, projectUrl) =
let Pack(workingDir,dependenciesFile : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, minimumFromLockFile, pinProjectReferences, interprojectReferencesConstraint, symbols, includeReferencedProjects, projectUrl) =
let buildConfig = defaultArg buildConfig "Release"
let buildPlatform = defaultArg buildPlatform ""
let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath)
Expand Down Expand Up @@ -214,7 +214,7 @@ let Pack(workingDir,dependenciesFile : DependenciesFile, packageOutputPath, buil
yield template, p
}
)
|> Seq.map (fun (t, p) -> findDependencies dependenciesFile buildConfig buildPlatform t p lockDependencies minimumFromLockFile pinProjectReferences projectTemplates includeReferencedProjects version cache)
|> Seq.map (fun (t, p) -> findDependencies dependenciesFile buildConfig buildPlatform t p lockDependencies minimumFromLockFile pinProjectReferences interprojectReferencesConstraint projectTemplates includeReferencedProjects version cache)
|> Seq.append remaining
|> Seq.toList

Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Versioning\Cache.fs" />
<Compile Include="Versioning\PackageSources.fs" />
<Compile Include="Versioning\Requirements.fs" />
<Compile Include="Versioning\InterprojectReferencesConstraint.fs" />
<Compile Include="Dependencies\GitCommandHelper.fs" />
<Compile Include="Dependencies\GitHandling.fs" />
<Compile Include="Dependencies\ModuleResolver.fs" />
Expand Down
Loading

0 comments on commit d9866d5

Please sign in to comment.