/// <summary> /// Adds a dependency to the current package. /// </summary> /// <param name="id">The identifier of the dependency.</param> /// <param name="version">The version of the dependency.</param> /// <param name="targetFramework">The target framework for the dependency.</param> /// <param name="includeAssets">An optional array of strings representing the assets to include for the dependency.</param> /// <param name="excludeAssets">An optional array of strings representing the assets to exclude from the dependency.</param> /// <returns>The current <see cref="PackageRepository" />.</returns> public PackageRepository Dependency(string id, string version, string targetFramework, string?includeAssets = "All", string?excludeAssets = "None") { if (LastPackage == null) { throw new InvalidOperationException(Strings.ErrorWhenAddingLibraryRequiresPackage); } LastPackage.AddTargetFramework(targetFramework); LastPackage.AddDependency(targetFramework, id, version, includeAssets, excludeAssets); SavePackageManifest(); return(this); }
/// <summary> /// Adds a library to the package. /// </summary> /// <param name="targetFramework">The target framework of the library.</param> /// <param name="filename">An optional filename for the library. The default value is <PackageId>.dll.</param> /// <param name="namespace">An optional namespace for the library. The default value is <PackageId>.</param> /// <param name="className">An optional class name for the library. The default value is <PackageId>_Class.</param> /// <param name="assemblyVersion">An optional assembly version for the library. The default value is "1.0.0.0"</param> /// <returns>The current <see cref="PackageRepository" />.</returns> public PackageRepository Library(string targetFramework, string?filename = null, string? @namespace = null, string?className = null, string assemblyVersion = "1.0.0.0") { if (LastPackage == null) { throw new InvalidOperationException(Strings.ErrorWhenAddingLibraryRequiresPackage); } if (string.IsNullOrWhiteSpace(filename)) { filename = $"{LastPackage.Id}.dll"; } if (string.IsNullOrWhiteSpace(@namespace)) { @namespace = LastPackage.Id; } if (string.IsNullOrWhiteSpace(className)) { className = $"{LastPackage.Id}_Class"; } LastPackage.AddTargetFramework(targetFramework); return(File( Path.Combine("lib", targetFramework, filename !), fileInfo => { fileInfo.Directory !.Create(); using (Stream stream = System.IO.File.Create(fileInfo.FullName)) { AssemblyCreator.Create(stream, Path.GetFileNameWithoutExtension(filename), @namespace !, className !, assemblyVersion, targetFramework); } })); }