Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to allow csproj being passed as a NuSpec file #644

Merged
merged 9 commits into from
Feb 19, 2015
50 changes: 31 additions & 19 deletions src/app/FakeLib/NuGet/NugetHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ let private replaceAccessKey key (text : string) =
if isNullOrEmpty key then text
else text.Replace(key, "PRIVATEKEY")

let private createNuspecFile parameters nuSpec =
let fi = fileInfo nuSpec
let specFile = parameters.WorkingDir @@ (fi.Name.Replace("nuspec", "") + parameters.Version + ".nuspec")
|> FullName
let private createNuSpecFromTemplate parameters (templateNuSpec:FileInfo) =
let specFile = parameters.WorkingDir @@ (templateNuSpec.Name.Replace("nuspec", "") + parameters.Version + ".nuspec")
|> FullName
tracefn "Creating .nuspec file at %s" specFile
fi.CopyTo(specFile, true) |> ignore

templateNuSpec.CopyTo(specFile, true) |> ignore

let getFrameworkGroup (frameworkTags : (string * string) seq) =
frameworkTags
Expand Down Expand Up @@ -213,6 +213,13 @@ let private createNuspecFile parameters nuSpec =
tracefn "Created nuspec file %s" specFile
specFile

let private createNuSpecFromTemplateIfNuSpecFile parameters nuSpecOrProjFile =
let nuSpecOrProjFileInfo = fileInfo nuSpecOrProjFile
match nuSpecOrProjFileInfo.Extension = ".nuspec" with
| true -> Some (createNuSpecFromTemplate parameters nuSpecOrProjFileInfo)
| false -> None


let private propertiesParam = function
| [] -> ""
| lst ->
Expand All @@ -233,11 +240,11 @@ let private pack parameters nuspecFile =

let execute args =
let result =
ExecProcess (fun info ->
ExecProcessAndReturnMessages (fun info ->
info.FileName <- parameters.ToolPath
info.WorkingDirectory <- FullName parameters.WorkingDir
info.Arguments <- args) parameters.TimeOut
if result <> 0 then failwithf "Error during NuGet package creation. %s %s" parameters.ToolPath args
if result.ExitCode <> 0 then failwithf "Error during NuGet package creation. %s %s\r\n%s" parameters.ToolPath args (toLines result.Errors)

let nuspecFile =
let fi = fileInfo nuspecFile
Expand Down Expand Up @@ -315,19 +322,21 @@ let rec private publishSymbols parameters =
///
/// - `setParams` - Function used to manipulate the default NuGet parameters.
/// - `nuspecFile` - The .nuspec file name.
let NuGetPack setParams nuspecFile =
traceStartTask "NuGetPack" nuspecFile
let NuGetPack setParams nuspecOrProjectFile =
traceStartTask "NuGetPack" nuspecOrProjectFile
let parameters = NuGetDefaults() |> setParams
try
let nuspecFile = createNuspecFile parameters nuspecFile
pack parameters nuspecFile
DeleteFile nuspecFile
match (createNuSpecFromTemplateIfNuSpecFile parameters nuspecOrProjectFile) with
| Some nuspecTemplateFile ->
pack parameters nuspecTemplateFile
DeleteFile nuspecTemplateFile
| None -> pack parameters nuspecOrProjectFile
with exn ->
(if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message
else exn.Message)
|> replaceAccessKey parameters.AccessKey
|> failwith
traceEndTask "NuGetPack" nuspecFile
traceEndTask "NuGetPack" nuspecOrProjectFile

/// Publishes a NuGet package to the nuget server.
/// ## Parameters
Expand All @@ -344,22 +353,25 @@ let NuGetPublish setParams =
///
/// - `setParams` - Function used to manipulate the default NuGet parameters.
/// - `nuspecFile` - The .nuspec file name.
let NuGet setParams nuspecFile =
traceStartTask "NuGet" nuspecFile
let NuGet setParams nuspecOrProjectFile =
traceStartTask "NuGet" nuspecOrProjectFile
let parameters = NuGetDefaults() |> setParams
try
let nuspecFile = createNuspecFile parameters nuspecFile
pack parameters nuspecFile
match (createNuSpecFromTemplateIfNuSpecFile parameters nuspecOrProjectFile) with
| Some nuspecTemplateFile ->
pack parameters nuspecTemplateFile
DeleteFile nuspecTemplateFile
| None -> pack parameters nuspecOrProjectFile

if parameters.Publish then
publish parameters
if parameters.ProjectFile <> null then publishSymbols parameters
DeleteFile nuspecFile
with exn ->
(if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message
else exn.Message)
|> replaceAccessKey parameters.AccessKey
|> failwith
traceEndTask "NuGet" nuspecFile
traceEndTask "NuGet" nuspecOrProjectFile

/// NuSpec metadata type
type NuSpecPackage =
Expand Down
66 changes: 65 additions & 1 deletion src/test/Test.FAKECore/PackageMgt/NugetSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,73 @@ public class when_packing_with_nuspec_template
};

Because of = () => NuGetHelper.NuGetPack(nugetParams, nuspecFile);

It should_create_nupkg_file = () => File.Exists(pkgFile).ShouldBeTrue();
}

public class when_packing_with_csproj_and_complete_nuspec_alongside
{
static string tempDir, pkgFile, projectFile;
static FSharpFunc<NuGetHelper.NuGetParams, NuGetHelper.NuGetParams> nugetParams;

Establish context = () =>
{
tempDir = Path.GetTempPath();
pkgFile = Path.Combine(tempDir, "fake_no_template.0.0.1.nupkg");
projectFile = Path.Combine(TestData.TestDataDir, "fake_no_template.csproj");

try { File.Delete(pkgFile); } catch (FileNotFoundException) { }

nugetParams = FSharpFuncUtil.ToFSharpFunc<NuGetHelper.NuGetParams, NuGetHelper.NuGetParams>(
p => new NuGetHelper.NuGetParams(
authors: ListModule.OfSeq(new[] { "author" }),
project: "fake",
description: "description",
outputPath: tempDir,
summary: "summary",
workingDir: TestData.TestDataDir,
version: "0.0.1",

files: ListModule.OfSeq(new[] { new Tuple<string, FSharpOption<string>, FSharpOption<string>>("*.*", FSharpOption<string>.None, FSharpOption<string>.None) }),

accessKey: p.AccessKey,
copyright: p.Copyright,
dependencies: p.Dependencies,
dependenciesByFramework: p.DependenciesByFramework,
includeReferencedProjects: p.IncludeReferencedProjects,
noDefaultExcludes: p.NoDefaultExcludes,
noPackageAnalysis: p.NoPackageAnalysis,
projectFile: p.ProjectFile,
properties: p.Properties,
publish: p.Publish,
publishTrials: p.PublishTrials,
publishUrl: p.PublishUrl,
references: p.References,
referencesByFramework: p.ReferencesByFramework,
releaseNotes: p.ReleaseNotes,
symbolPackage: p.SymbolPackage,
tags: p.Tags,
timeOut: p.TimeOut,
title: p.Title,
toolPath: p.ToolPath
)
);
};


private Because of = () =>
{
if (!EnvironmentHelper.isMono)
{
NuGetHelper.NuGetPack(nugetParams, projectFile);
};
};
It should_create_nupkg_file = () =>
{
File.Exists(pkgFile).ShouldBeTrue();
if (!EnvironmentHelper.isMono)
{
File.Exists(pkgFile).ShouldBeTrue();
}
};
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/Test.FAKECore/Test.FAKECore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@
<Content Include="TestData\AllObjects_2.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestData\bin\Debug\TestNuGetPack.dll">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these files are gitignored. You need to add them "forced"

<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestData\bin\Debug\TestNuGetPack.pdb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestData\fake_complete.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -234,10 +240,17 @@
<Content Include="TestData\nuget.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\fake_no_template.csproj">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="TestData\fake.nuspec">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\fake_no_template.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
Expand Down
Binary file not shown.
Binary file not shown.
53 changes: 53 additions & 0 deletions src/test/Test.FAKECore/TestData/fake_no_template.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0D71FF59-482C-4CC2-A068-351C9FCF5555}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestNuGetPack</RootNamespace>
<AssemblyName>TestNuGetPack</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
20 changes: 20 additions & 0 deletions src/test/Test.FAKECore/TestData/fake_no_template.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<description>description</description>
<id>fake_no_template</id>
<version>0.0.1</version>
<authors>author</authors>
<language>en-US</language>
<summary>summary</summary>
<projectUrl>http://www.github.com/fsharp/Fake</projectUrl>
<licenseUrl>http://www.github.com/fsharp/Fake/blob/master/License.txt</licenseUrl>
<iconUrl>https://raw.githubusercontent.com/fsharp/FAKE/master/help/pics/logo.png</iconUrl>
<releaseNotes></releaseNotes>
<tags>build, fake, f#</tags>
<dependencies></dependencies>
</metadata>
<files>
<file src="*.*" />
</files>
</package>