private IPackage BuildFromProjectFile(string path) { var factory = new ProjectFactory(path, Properties) { IsTool = Tool, Logger = Console, Build = Build, }; // Create a builder for the main package as well as the sources/symbols package PackageBuilder mainPackageBuilder = factory.CreateBuilder(BasePath); // Build the main package IPackage package = BuildPackage(mainPackageBuilder); // If we're excluding symbols then do nothing else if (!Symbols) { return package; } Console.WriteLine(); Console.WriteLine(NuGetResources.PackageCommandAttemptingToBuildSymbolsPackage, Path.GetFileName(path)); factory.IncludeSymbols = true; PackageBuilder symbolsBuilder = factory.CreateBuilder(BasePath); symbolsBuilder.Version = mainPackageBuilder.Version; // Get the file name for the sources package and build it string outputPath = GetOutputPath(symbolsBuilder, symbols: true); BuildPackage(symbolsBuilder, outputPath); // this is the real package, not the symbol package return package; }
private IPackage BuildFromProjectFile(string path) { var factory = new ProjectFactory(path, Properties) { IsTool = Tool, Logger = Console, Build = Build, IncludeReferencedProjects = IncludeReferencedProjects }; // Add the additional Properties to the properties of the Project Factory foreach (var property in Properties) { if (factory.ProjectProperties.ContainsKey(property.Key)) { Console.WriteWarning(LocalizedResourceManager.GetString("Warning_DuplicatePropertyKey"), property.Key); } factory.ProjectProperties[property.Key] = property.Value; } // Create a builder for the main package as well as the sources/symbols package PackageBuilder mainPackageBuilder = factory.CreateBuilder(BasePath); // Build the main package IPackage package = BuildPackage(mainPackageBuilder); // If we're excluding symbols then do nothing else if (!Symbols) { return package; } Console.WriteLine(); Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandAttemptingToBuildSymbolsPackage"), Path.GetFileName(path)); factory.IncludeSymbols = true; PackageBuilder symbolsBuilder = factory.CreateBuilder(BasePath); symbolsBuilder.Version = mainPackageBuilder.Version; // Get the file name for the sources package and build it string outputPath = GetOutputPath(symbolsBuilder, symbols: true); BuildPackage(symbolsBuilder, outputPath); // this is the real package, not the symbol package return package; }
private void BuildFromProjectFile(string path) { var factory = new ProjectFactory(path) { IsTool = Tool, Logger = Console }; // Specify the configuration factory.Properties.Add("Configuration", Configuration ?? "Release"); // Create a builder for the main package as well as the sources/symbols package PackageBuilder mainPackageBuilder = factory.CreateBuilder(); // Build the main package BuildPackage(path, mainPackageBuilder); // If we're excluding symbols then do nothing else if (!Symbols) { return; } Console.WriteLine(); Console.WriteLine(NuGetResources.PackageCommandAttemptingToBuildSymbolsPackage, Path.GetFileName(path)); factory.IncludeSymbols = true; PackageBuilder symbolsBuilder = factory.CreateBuilder(); // Get the file name for the sources package and build it string outputPath = GetOutputPath(symbolsBuilder, symbols: true); BuildPackage(path, symbolsBuilder, outputPath); }
public void ProjectFactoryAppliesGlobalProperties() { // Arrange var testAssembly = Assembly.GetExecutingAssembly(); var projectXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <ProjectGuid>{F879F274-EFA0-4157-8404-33A19B4E6AEC}</ProjectGuid> <OutputType>Library</OutputType> <RootNamespace>NuGet.Test</RootNamespace> <AssemblyName>" + testAssembly.GetName().Name + @"</AssemblyName> <TargetFrameworkProfile Condition="" '$(TargetFrameworkVersion)' == 'v4.0' "">Client</TargetFrameworkProfile> <OutputPath>.</OutputPath> <!-- Force it to look for the assembly in the base path --> </PropertyGroup> <ItemGroup> <Compile Include=""..\..\Dummy.cs""> <Link>Dummy.cs</Link> </Compile> </ItemGroup> <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" /> <Import Project=""C:\DoesNotExist.targets"" Condition="" '$(MyGlobalProperty)' != 'true' "" /> </Project>"; // Set base path to the currently assembly's folder so that it will find the test assembly var basePath = Path.GetDirectoryName(testAssembly.CodeBase); var cmdLineProperties = new Dictionary<string, string> { { "MyGlobalProperty", "true" } }; var project = new Project(XmlReader.Create(new StringReader(projectXml)), cmdLineProperties, null); project.FullPath = Path.Combine(project.DirectoryPath, "test.csproj"); // Act var factory = new ProjectFactory(project) { Build = false }; factory.ProjectProperties.Add("MyGlobalProperty", "false"); // This shouldn't be applied factory.ProjectProperties.Add("TestProperty", "true"); // This should be applied var packageBuilder = factory.CreateBuilder(basePath); // Assert Assert.True(project.GetProperty("MyGlobalProperty").IsGlobalProperty); Assert.False(project.GetProperty("TestProperty").IsGlobalProperty); Assert.Equal("true", project.GetProperty("MyGlobalProperty").UnevaluatedValue, StringComparer.OrdinalIgnoreCase); Assert.Equal("true", project.GetProperty("TestProperty").UnevaluatedValue, StringComparer.OrdinalIgnoreCase); }
public void ProjectFactoryInitializesPropertiesForPreprocessorFromAssemblyMetadata() { // Arrange var testAssembly = Assembly.GetExecutingAssembly(); const string inputSpec = @"<?xml version=""1.0""?> <package> <metadata> <id>$id$</id> <version>$version$</version> <description>$description$</description> <authors>$owner$</authors> <copyright>$copyright$</copyright> <licenseUrl>http://nuget.codeplex.com/license</licenseUrl> <projectUrl>http://nuget.codeplex.com</projectUrl> <tags>nuget</tags> </metadata> </package>"; var projectXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <ProjectGuid>{F879F274-EFA0-4157-8404-33A19B4E6AEC}</ProjectGuid> <OutputType>Library</OutputType> <RootNamespace>NuGet.Test</RootNamespace> <AssemblyName>" + testAssembly.GetName().Name + @"</AssemblyName> <TargetFrameworkProfile Condition="" '$(TargetFrameworkVersion)' == 'v4.0' "">Client</TargetFrameworkProfile> <OutputPath>.</OutputPath> <!-- Force it to look for the assembly in the base path --> </PropertyGroup> <ItemGroup> <Compile Include=""..\..\Dummy.cs""> <Link>Dummy.cs</Link> </Compile> </ItemGroup> <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" /> </Project>"; // Set base path to the currently assembly's folder so that it will find the test assembly var basePath = Path.GetDirectoryName(testAssembly.CodeBase); var project = new Project(XmlReader.Create(new StringReader(projectXml))); project.FullPath = Path.Combine(project.DirectoryPath, "test.csproj"); // Act var factory = new ProjectFactory(project) { Build = false }; var packageBuilder = factory.CreateBuilder(basePath); var actual = Preprocessor.Process(inputSpec.AsStream(), factory, false); // assert var expected = @"<?xml version=""1.0""?> <package> <metadata> <id>" + testAssembly.GetName().Name + @"</id> <version>" + testAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion + @"</version> <description></description> <authors>Outercurve</authors> <copyright>" + testAssembly.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright + @"</copyright> <licenseUrl>http://nuget.codeplex.com/license</licenseUrl> <projectUrl>http://nuget.codeplex.com</projectUrl> <tags>nuget</tags> </metadata> </package>"; Assert.Equal(expected, actual); }