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

Reworked test/Fix for #1477 (locked files after restore) #1492

Merged
merged 2 commits into from Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions integrationtests/Paket.IntegrationTests/BindingRedirect.fs
Expand Up @@ -316,4 +316,19 @@ let ``#1248 redirects off with --redirects``() =
let originalConfig = File.ReadAllText(originalConfigPath)

config |> shouldEqual originalConfig

[<Test>]
let ``#1477 assembly redirects lock files``() =
let scenario = "i001474-restore-no-locks"
prepare scenario
let p = Paket.Dependencies.Locate (Path.Combine(scenarioTempPath scenario, "paket.dependencies"))
p.Install(true,true)
p.Restore()

try
Directory.Delete(scenarioTempPath scenario, true)
with e ->
failwith "could not delete directory, i.e. restore holds on to files"



@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{673951A0-5216-4FBD-BA08-7FA057D5CC0D}"
ProjectSection(SolutionItems) = preProject
..\paket.dependencies = ..\paket.dependencies
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyClassLibrary", "MyClassLibrary\MyClassLibrary.csproj", "{CD678800-8DFC-4BB1-911A-7234F492EA29}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CD678800-8DFC-4BB1-911A-7234F492EA29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD678800-8DFC-4BB1-911A-7234F492EA29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD678800-8DFC-4BB1-911A-7234F492EA29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD678800-8DFC-4BB1-911A-7234F492EA29}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyClassLibrary
{
public class Class1
{
}
}
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>{CD678800-8DFC-4BB1-911A-7234F492EA29}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyClassLibrary</RootNamespace>
<AssemblyName>MyClassLibrary</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.Net.Http" />
<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>
-->
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5.1'">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MyClassLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MyClassLibrary")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("cd678800-8dfc-4bb1-911a-7234f492ea29")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1 @@
Newtonsoft.Json framework: net451
@@ -0,0 +1,3 @@
source https://www.nuget.org/api/v2/

nuget Newtonsoft.Json
39 changes: 23 additions & 16 deletions src/Paket.Core/InstallProcess.fs
Expand Up @@ -159,9 +159,27 @@ let CreateModel(root, force, dependenciesFile:DependenciesFile, lockFile : LockF
|> Seq.concat
|> Seq.toArray

/// Since Assembly.ReflectionOnlyLoadFrom holds on to file handles indefintely, we use
/// ReflectionOnlyLoad(bytes[]) instead. However, in order to prevent
/// CLR from loading same assemblies multiple times (results in exn), we use a static
/// dictionary for caching assemblies, based on their filename.
module private LoadAssembliesSafe =

let loadedLibs = new Dictionary<_,_>()

let reflectionOnlyLoadFrom library =
let key = FileInfo(library).FullName.ToLowerInvariant()
match loadedLibs.TryGetValue key with
| (true,v) -> v
| _ ->
let assemblyAsBytes = File.ReadAllBytes library
let v = Assembly.ReflectionOnlyLoad assemblyAsBytes
loadedLibs.[key] <- v
v


/// Applies binding redirects for all strong-named references to all app. and web.config files.
let private applyBindingRedirects (loadedLibs:Dictionary<_,_>) isFirstGroup createNewBindingFiles cleanBindingRedirects redirects root groupName findDependencies extractedPackages =
let private applyBindingRedirects isFirstGroup createNewBindingFiles cleanBindingRedirects redirects root groupName findDependencies extractedPackages =
let dependencyGraph = ConcurrentDictionary<_,Set<_>>()
let projects = ConcurrentDictionary<_,ProjectFile option>();
let referenceFiles = ConcurrentDictionary<_,ReferencesFile option>();
Expand Down Expand Up @@ -209,18 +227,7 @@ let private applyBindingRedirects (loadedLibs:Dictionary<_,_>) isFirstGroup crea
|> Seq.choose(fun (library,redirects) ->
try
let key = FileInfo(library).FullName.ToLowerInvariant()
let assembly =
match loadedLibs.TryGetValue key with
| true,v -> v
| _ ->
let tempFile = Path.GetTempFileName()
if File.Exists(tempFile) then
File.Delete tempFile
File.Copy(library,tempFile)
let v = Assembly.ReflectionOnlyLoadFrom library
loadedLibs.Add(key,v)
File.Delete tempFile
v
let assembly = LoadAssembliesSafe.reflectionOnlyLoadFrom library

Some (assembly, BindingRedirects.getPublicKeyToken assembly, assembly.GetReferencedAssemblies(), redirects)
with exn -> None)
Expand Down Expand Up @@ -388,8 +395,7 @@ let InstallIntoProjects(options : InstallerOptions, forceTouch, dependenciesFile

processContentFiles root project usedPackages gitRemoteItems options
project.Save forceTouch
let loadedLibs = new Dictionary<_,_>()


let first = ref true

let redirects =
Expand All @@ -408,9 +414,10 @@ let InstallIntoProjects(options : InstallerOptions, forceTouch, dependenciesFile
|> Option.bind (fun p -> p.Settings.CreateBindingRedirects)

(snd kv.Value,packageRedirects))
|> applyBindingRedirects loadedLibs !first options.CreateNewBindingFiles options.Hard (g.Value.Options.Redirects ++ redirects) (FileInfo project.FileName).Directory.FullName g.Key lockFile.GetAllDependenciesOf
|> applyBindingRedirects !first options.CreateNewBindingFiles options.Hard (g.Value.Options.Redirects ++ redirects) (FileInfo project.FileName).Directory.FullName g.Key lockFile.GetAllDependenciesOf
first := false


/// Installs all packages from the lock file.
let Install(options : InstallerOptions, forceTouch, dependenciesFile, lockFile : LockFile) =
let root = FileInfo(lockFile.FileName).Directory.FullName
Expand Down