Skip to content
This repository was archived by the owner on May 30, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Install/NuBuild.wxs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- See http://stackoverflow.com/questions/471424/wix-tricks-and-tips -->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?define ProductVersion = "1.9.0"?>
<?define ProductVersion = "1.9.1"?>
<Product Id="*"
UpgradeCode="1948F590-CD4C-4279-9466-5A172FEA8FCE"
Name="NuBuild Project System"
Expand Down
6 changes: 6 additions & 0 deletions MSBuild/Config/NuBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
(eg. lib\net40) based on TargetFrameworkVersion
-->
<NuBuildAddBinariesToSubfolder Condition="'$(NuBuildAddBinariesToSubfolder)' == ''">false</NuBuildAddBinariesToSubfolder>
<!-- Properties: NuBuildAutoGenerateDependencies
. If the .nuspec does not contain a <dependencies> xml block, setting this to true will auto-generate one
based on the project's packages.config file. Defaults to true.
-->
<NuBuildAutoGenerateDependencies Condition="'$(NuBuildAutoGenerateDependencies)' == ''">true</NuBuildAutoGenerateDependencies>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == '' and '$(TargetFrameworkProfile)' != ''">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion),Profile=$(TargetFrameworkProfile)</TargetFrameworkMoniker>
<TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == ''">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
Expand Down Expand Up @@ -103,6 +108,7 @@
OutputPath="$(OutputPath)"
ReferenceLibraries="@(__ReferenceLibraries)"
AddBinariesToSubfolder="$(NuBuildAddBinariesToSubfolder)"
AutoGenerateDependencies="$(NuBuildAutoGenerateDependencies)"
IncludePdbs="$(NuBuildIncludePdbs)"/>
<Message Text="%(NuPrepared.Filename) -> %(NuPrepared.NuPackagePath)" Importance="high"/>
<CallTarget Targets="__CopySourceItemsToOutputDirectory"/>
Expand Down
106 changes: 105 additions & 1 deletion MSBuild/Tasks/NuPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
// System References
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Versioning;
using System.Xml.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
Expand All @@ -44,6 +46,7 @@ namespace NuBuild.MSBuild
public sealed class NuPackage : Task, NuGet.IPropertyProvider
{
private Project propertyProject = null;
private const string PACKAGES_CONFIG = "packages.config";

#region Task Parameters
/// <summary>
Expand Down Expand Up @@ -72,6 +75,10 @@ public sealed class NuPackage : Task, NuGet.IPropertyProvider
/// </summary>
public Boolean AddBinariesToSubfolder { get; set; }
/// <summary>
/// If nuspec dependencies is not defined, creates it based on project packages.config file.
/// </summary>
public Boolean AutoGenerateDependencies { get; set; }
/// <summary>
/// Specifies whether to add PDB files for binaries
/// automatically to the package
/// </summary>
Expand Down Expand Up @@ -127,11 +134,108 @@ private void BuildPackage (ITaskItem specItem)
// add a new file to the folder for each project
// referenced by the current project
AddLibraries(builder);

//auto generate package dependencies from packages.config file.
if (AutoGenerateDependencies && !builder.DependencySets.Any())
AddDependencies(builder);

// write the configured package out to disk
var pkgPath = specItem.GetMetadata("NuPackagePath");
using (var pkgFile = File.Create(pkgPath))
builder.Save(pkgFile);
}

/// <summary>
/// Go through each referenced project, and add any nuget dependencies from
/// their packages.config file. Ignores any that have developerDependency=true
/// </summary>
/// <param name="builder"></param>
private void AddDependencies(NuGet.PackageBuilder builder)
{
Dictionary<string, string> NugetPackages = new Dictionary<string, string>();

string projectRoot = Path.GetDirectoryName(this.ProjectPath);

XElement root = XElement.Load(this.ProjectPath);
var ns = root.Name.Namespace;
var elems = (from el in root.Descendants(ns + "ProjectReference")
select el).ToList();

if (elems.Any())
{
foreach (var item in elems)
{
string itemPath = item.Attribute("Include").Value;
string packagesPath = Path.GetFullPath(Path.Combine(projectRoot, Path.GetDirectoryName(itemPath))) + Path.DirectorySeparatorChar + PACKAGES_CONFIG;
GetNuGetDependencies(packagesPath, NugetPackages);
}
}

if (NugetPackages.Any())
AddNugetDependencies(builder, NugetPackages);
}

/// <summary>
/// Inserts a dependency set into the packagebuilder object, based on a dictionary
/// containing Id/version pairs (Newtonsoft.json, 5.0.6 for example).
/// </summary>
/// <param name="builder"></param>
/// <param name="packages"></param>
private void AddNugetDependencies(NuGet.PackageBuilder builder, Dictionary<string, string> packages)
{
//add dependencies
List<PackageDependency> dependencies = new List<PackageDependency>();
foreach (var package in packages)
{
dependencies.Add(new PackageDependency(package.Key, new VersionSpec {MinVersion = new SemanticVersion(package.Value), IsMinInclusive = true}));
}

var set = new PackageDependencySet(null, dependencies);
builder.DependencySets.Add(set);
}

/// <summary>
/// opens a packages.config file (if exists) and parses the nuget packages into a dictionary.
/// dictionary key is the package id (ie, newtownsoft.json), and version is the semantic version string (ie 5.0.6)
/// if there are 2 csproj's linked to the same nuproj, this also verifies that any shared packages share the same version.
/// if they do not, throws an exception and stops.
/// </summary>
/// <param name="packagesPath"></param>
/// <param name="packages"></param>
private void GetNuGetDependencies(string packagesPath, Dictionary<string, string> packages)
{
if (!File.Exists(packagesPath)) return; //packages.config is not there, no nuget packages in project.

XElement root = XElement.Load(packagesPath);
var elems = from el in root.Elements("package")
where el.Attribute("developmentDependency") == null || (string)el.Attribute("developmentDependency") == "false"
select el;

foreach (var item in elems)
{
var id = item.Attribute("id").Value;
var version = item.Attribute("version").Value;

if (packages.ContainsKey(id))
{
//if version is the same, ok, but if different, then that means the same package
//is referenced with 2 different versions. (most likely from 2 different .csproj's linked in one nuproj,
//and not utilizing the same version of the nuget package.
if (packages[id] != version)
{
Log.LogError(
"package {0} is referenced twice, with different versions. Cannot proceed with the auto generation of dependencies. Please update to use the same version or manually create the dependencies in the nuspec file. Versions detected: {1}, {2}",
id, packages[id], version);
throw new Exception("Could not auto-generate dependencies due to multiple versions of same package.");
}
}
else
{
packages.Add(id, version);
}
}
}

/// <summary>
/// Adds project references to the package lib section
/// </summary>
Expand Down Expand Up @@ -173,7 +277,7 @@ private void AddLibraries (NuGet.PackageBuilder builder)
if (!String.IsNullOrWhiteSpace(targetFrameworkName))
tgtFolder = Path.Combine(tgtFolder, VersionUtility.GetShortFrameworkName(new FrameworkName(targetFrameworkName)));
}
catch { }
catch { }
// add the source library file to the package
builder.Files.Add(
new NuGet.PhysicalPackageFile()
Expand Down
4 changes: 2 additions & 2 deletions MSBuild/Tasks/NuPrepare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public sealed class NuPrepare : Task
public override Boolean Execute ()
{
try
{
{
// parepare the task for execution
if (this.ReferenceLibraries == null)
this.ReferenceLibraries = new ITaskItem[0];
Expand All @@ -129,7 +129,7 @@ public override Boolean Execute ()
PreparePackage(specItem);
// return the list of build sources/targets
this.Sources = this.sourceList.ToArray();
this.Targets = this.targetList.ToArray();
this.Targets = this.targetList.ToArray();
}
catch (Exception e)
{
Expand Down
7 changes: 5 additions & 2 deletions MSBuild/Tasks/Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build" />
Expand All @@ -35,11 +37,12 @@
<Reference Include="Microsoft.Web.XmlTransform">
<HintPath>..\..\packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
</Reference>
<Reference Include="NuGet.Core, Version=2.7.40808.167, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="NuGet.Core, Version=2.8.50126.400, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Nuget.Core.2.7.0\lib\net40-Client\NuGet.Core.dll</HintPath>
<HintPath>..\..\packages\NuGet.Core.2.8.0\lib\net40-Client\NuGet.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions MSBuild/Tasks/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Xdt" version="1.0.0" targetFramework="net40" />
<package id="NuGet.Core" version="2.7.0" targetFramework="net40" />
<package id="NuGet.Core" version="2.8.0" targetFramework="net40" />
</packages>
20 changes: 20 additions & 0 deletions VS/Package/NuBuild/NuBuildPropertyPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public sealed class NuBuildPropertyPage : SettingsPage
private VersionSource versionSource;
private Boolean versionFileName;
private Boolean addBinariesToSubfolder;
private Boolean autoGenerateDependencies;
private Boolean includePdbs;
private TargetFramework targetFramework;

Expand Down Expand Up @@ -128,6 +129,18 @@ public Boolean AddBinariesToSubfolder
set { this.addBinariesToSubfolder = value; this.IsDirty = true; }
}

/// <summary>
/// If nuspec dependencies is not defined, creates it based on project packages.config file.
/// </summary>
[Category("Advanced")]
[DisplayName("Auto Generate Dependencies")]
[Description(@"If nuspec dependencies is not defined, creates it based on project packages.config file.")]
public Boolean AutoGenerateDependencies
{
get { return this.autoGenerateDependencies; }
set { this.autoGenerateDependencies = value; this.IsDirty = true; }
}

/// <summary>
/// Specifies whether to include PDBs for referenced assemblies
/// </summary>
Expand Down Expand Up @@ -165,6 +178,9 @@ protected override void BindProperties ()
this.addBinariesToSubfolder = Boolean.Parse(
this.ProjectMgr.GetProjectProperty("NuBuildAddBinariesToSubfolder")
);
this.autoGenerateDependencies = Boolean.Parse(
this.ProjectMgr.GetProjectProperty("NuBuildAutoGenerateDependencies")
);
this.includePdbs = Boolean.Parse(
this.ProjectMgr.GetProjectProperty("NuBuildIncludePdbs")
);
Expand Down Expand Up @@ -207,6 +223,10 @@ protected override Int32 ApplyChanges ()
"NuBuildAddBinariesToSubfolder",
this.addBinariesToSubfolder.ToString()
);
this.ProjectMgr.SetProjectProperty(
"NuBuildAutoGenerateDependencies",
this.autoGenerateDependencies.ToString()
);
this.ProjectMgr.SetProjectProperty(
"NuBuildIncludePdbs",
this.includePdbs.ToString()
Expand Down
1 change: 1 addition & 0 deletions VS/ProjectTemplate/NuProj/NuProj.nuproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<NuBuildVersionSource>library</NuBuildVersionSource>
<NuBuildVersionFileName>true</NuBuildVersionFileName>
<NuBuildAddBinariesToSubfolder>false</NuBuildAddBinariesToSubfolder>
<NuBuildAutoGenerateDependencies>true</NuBuildAutoGenerateDependencies>
<NuBuildIncludePdbs>false</NuBuildIncludePdbs>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"></PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
// System References
using System.Reflection;
// Project References
[assembly:AssemblyVersion("1.9.0.0")]
[assembly:AssemblyFileVersion("1.9.0.0")]
[assembly:AssemblyVersion("1.9.1.0")]
[assembly:AssemblyFileVersion("1.9.1.0")]