public override void Run() { if (System.IO.File.Exists(File)) { System.IO.File.Delete(File); } PackageRestoreData packageRestoreData = new PackageRestoreData { ProjectJsonPath = Input .FirstOrDefault(i => i.ItemSpec.Equals("ProjectJsonPath", StringComparison.OrdinalIgnoreCase))? .GetMetadata("value"), RestoreProjectStyle = Input .FirstOrDefault(i => i.ItemSpec.Equals("RestoreProjectStyle", StringComparison.OrdinalIgnoreCase))? .GetMetadata("value"), RestoreOutputAbsolutePath = Input .FirstOrDefault(i => i.ItemSpec.Equals("RestoreOutputAbsolutePath", StringComparison.OrdinalIgnoreCase))? .GetMetadata("value"), PackageImportOrder = Input .Where(i => i.ItemSpec.Equals("PackageReference", StringComparison.OrdinalIgnoreCase) && !String.IsNullOrWhiteSpace(i.GetMetadata("id"))) .Select(i => new RestorePackage(i.GetMetadata("id"), i.GetMetadata("version"))).ToList() }; Directory.CreateDirectory(Path.GetDirectoryName(File)); System.IO.File.WriteAllText(File, JsonConvert.SerializeObject(packageRestoreData, Formatting.Indented)); }
public void VerifyPackageReferenceParserTest() { string projectPackageReferenceFile = Path.Combine(TestRootPath, "foo.proj"); string projectAssetsJsonFile = Path.Combine(TestRootPath, "project.assets.json"); PackageRestoreData packageRestoreData = LoadPackageRestoreObject(projectPackageReferenceFile, GetTempFileName(), _packageReferenceRestoreFlagContents.Replace("#RestoreOutputPath#", TestRootPath.Replace(@"\", @"\\"))); CreateProjectAssetsJsonFile(projectAssetsJsonFile, (new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") })); string packagePath = CreatePackagesFolder(new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") }, @"\"); MockSettings settings = new MockSettings { { "config", new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "globalPackagesFolder", packagePath }, } } }; bool result = new NuGetPackageReferenceProjectParser(settings, _log).TryGetPackages(packagePath, packageRestoreData, out IEnumerable <PackageIdentityWithPath> packages); result.ShouldBeTrue(); IList <PackageIdentityWithPath> packageIdentityWithPaths = packages as IList <PackageIdentityWithPath> ?? packages.ToList(); packageIdentityWithPaths.Count.ShouldBe(1); packageIdentityWithPaths.First().Id.ShouldBe("Newtonsoft.Json"); packageIdentityWithPaths.First().Version.ToString().ShouldBe("6.0.3"); }
public void ReadJsonFileTest() { PackageRestoreData packageRestoreData = LoadPackageRestoreObject("foo.proj", GetTempFileName(), _packageReferenceRestoreFlagContents); packageRestoreData.RestoreProjectStyle.ShouldBe("PackageReference"); packageRestoreData.ProjectJsonPath.ShouldBe(string.Empty); packageRestoreData.RestoreOutputAbsolutePath.ShouldBe("#RestoreOutputPath#"); packageRestoreData.PackageImportOrder.Count.ShouldBe(1); packageRestoreData.PackageImportOrder.First().Id.ShouldBe("Newtonsoft.Json"); packageRestoreData.PackageImportOrder.First().Version.ShouldBe("6.0.3"); }
public void AddUnrestoredPackageForProject (string projectName, string solutionDirectory) { var packageReference = new PackageReference ( new PackageIdentity ("Test", new NuGetVersion ("1.0")), new NuGetFramework ("any")); var restoreData = new PackageRestoreData ( packageReference, new [] { projectName }, isMissing: true); var restoreDataList = new List<PackageRestoreData> (); restoreDataList.Add (restoreData); PackagesInSolution[solutionDirectory] = restoreDataList; }
public void ValidateProjectJsonNugetPropertyGeneratorTest() { string projectJsonFile = Path.Combine(TestRootPath, "project.json"); string projectLockJsonFile = Path.Combine(TestRootPath, "project.lock.json"); File.WriteAllText(projectJsonFile, _packageProjectJsonFileContents); string packageProjectJsonRestoreFlagContents = _packageProjectJsonRestoreFlagContents.Replace("#JsonFile#", projectJsonFile.Replace(@"\", @"\\")); PackageRestoreData packageRestoreData = LoadPackageRestoreObject(projectJsonFile, GetTempFileName(), packageProjectJsonRestoreFlagContents); CreateProjectJsonLockFile(projectLockJsonFile, new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") }); string outputFile = Path.Combine(TestRootPath, "output.props"); string expectedOutputContent = $@"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> <NuGetPath_Newtonsoft_Json>{TestRootPath}\packages\newtonsoft.json\6.0.3</NuGetPath_Newtonsoft_Json> <NuGetVersion_Newtonsoft_Json>6.0.3</NuGetVersion_Newtonsoft_Json> </PropertyGroup> <ItemGroup> <CBTNuGetPackageDir Include=""{TestRootPath}\packages\newtonsoft.json\6.0.3"" /> </ItemGroup> </Project>"; string packagePath = CreatePackagesFolder(new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") }, @"\"); MockSettings settings = new MockSettings { { "config", new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "globalPackagesFolder", packagePath }, } } }; new NuGetPropertyGenerator(_log, settings, projectJsonFile).Generate(outputFile, "NuGetVersion_", "NuGetPath_", packageRestoreData); _log.HasLoggedErrors.ShouldBeFalse(); File.Exists(outputFile).ShouldBe(true); File.ReadAllText(outputFile).NormalizeNewLine().ShouldBe(expectedOutputContent.NormalizeNewLine()); }
public void AddUnrestoredPackageForProject(string projectName, string solutionDirectory) { var packageReference = new PackageReference( new PackageIdentity("Test", new NuGetVersion("1.0")), new NuGetFramework("any")); var restoreData = new PackageRestoreData( packageReference, new [] { projectName }, isMissing: true); var restoreDataList = new List <PackageRestoreData> (); restoreDataList.Add(restoreData); PackagesInSolution[solutionDirectory] = restoreDataList; }
bool IsMissingForProject(PackageRestoreData package) { if (!package.IsMissing) { return(false); } foreach (string projectName in package.ProjectNames) { foreach (IDotNetProject dotNetProject in dotNetProjects) { if (dotNetProject.Name == projectName) { return(true); } } } return(false); }
public void VerifyPackagesConfigParserTest() { string packageConfigFile = Path.Combine(TestRootPath, "packages.config"); PackageRestoreData packageRestoreData = LoadPackageRestoreObject(packageConfigFile, GetTempFileName(), _packageConfigRestoreFlagContents); File.WriteAllText(packageConfigFile, _packageConfigFileContents); string packagePath = CreatePackagesFolder(new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.1"), new Tuple <string, string>("Newtonsoft.Json", "7.0.1") }); MockSettings settings = new MockSettings { { "config", new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "repositoryPath", packagePath }, } } }; bool result = new NuGetPackagesConfigParser(settings, _log).TryGetPackages(packageConfigFile, packageRestoreData, out IEnumerable <PackageIdentityWithPath> packages); result.ShouldBeTrue(); packageConfigFile = Path.Combine(TestRootPath, "foo.proj"); packageRestoreData = LoadPackageRestoreObject(packageConfigFile, GetTempFileName(), _packageConfigRestoreFlagContents); result = new NuGetPackagesConfigParser(settings, _log).TryGetPackages(packageConfigFile, packageRestoreData, out packages); result.ShouldBeTrue(); IList <PackageIdentityWithPath> packageIdentityWithPaths = packages as IList <PackageIdentityWithPath> ?? packages.ToList(); packageIdentityWithPaths.Count.ShouldBe(2); packageIdentityWithPaths.Select(i => i.Id).ShouldBe(new [] { "Newtonsoft.Json", "Newtonsoft.Json" }); packageIdentityWithPaths.Select(i => i.Version.ToString()).ShouldBe(new[] { "6.0.1", "7.0.1" }); }
bool IsMissingForCurrentProject(PackageRestoreData package) { return(package.IsMissing && package.ProjectNames.Any(name => name == projectName)); }
bool IsMissingForCurrentProject (PackageRestoreData package) { return package.IsMissing && package.ProjectNames.Any (name => name == projectName); }