public void BuildPackage(string baseUrl, ManifestMetadata metadata, ManifestFile[] files)
 {
     NuGet.PackageBuilder packageBuilder = new NuGet.PackageBuilder();
     packageBuilder.Populate(metadata);
     packageBuilder.PopulateFiles(baseUrl, files);
     var saveDir = Path.Combine(DEFAULT_PACKAGES_SAVE_PATH, packageBuilder.Id, packageBuilder.Version.ToString().Replace('.', '_'));
     Directory.CreateDirectory(saveDir);
     var saveStream = File.Create(Path.Combine(saveDir, packageBuilder.Id + ".nupkg"));
     packageBuilder.Save(saveStream);
 }
Exemple #2
0
 /// <summary>
 /// Specifies a file to be included in the package
 /// </summary>
 /// <param name="source">The location of the file or files to include. The path is relative to the NuSpec file unless an absolute path is specified. The wildcard character, *, is allowed. Using a double wildcard, **, implies a recursive directory search.</param>
 /// <param name="target">This is a relative path to the directory within the package where the source files will be placed.</param>
 /// <param name="exclude">The file or files to exclude. This is usually combined with a wildcard value in the `src` attribute. The `exclude` attribute can contain a semi-colon delimited list of files or a file pattern. Using a double wildcard, **, implies a recursive exclude pattern.</param>
 public void AddFile(string source, string target, string exclude = "")
 {
     var mf = new ManifestFile() { Exclude = exclude, Source = source, Target = target };
     _manifest.Files.Add(mf);
 }
Exemple #3
0
        static ManifestFile ManifestFileForContent(string contentPath){
            var contentlist = contentPath.Split(",".ToCharArray());
            var source = contentlist[0];
            var target = contentlist.Length > 1 ? contentlist[1] : contentlist[0];

            bool exists = false;
            if (source.Contains("/")) {

                if(source.Contains("/**/")){
                    var dir = source.Substring(0, source.LastIndexOf("/**/"));
                    var pattern = source.Substring(source.LastIndexOf("/**/") + 4);
                    string [] subdirectoryEntries = Directory.GetDirectories(dir);
                    foreach (string subdirectory in subdirectoryEntries) {
                        var subdirectory2 = subdirectory.Substring(subdirectory.LastIndexOf("/") + 1);
                        var source2 = source.Replace("/**/", "/" + subdirectory2 + "/");
                        var dir2 = source2.Substring(0, source2.LastIndexOf("/"));
                        var pattern2 = source2.Substring(source2.LastIndexOf("/") + 1);
                        try{
                            Directory.EnumerateFiles(dir2, pattern2).Any();
                            exists = true;
                            break;
                        }catch(Exception){
                        }
                    }
                } else {
                    var dir = source.Substring(0, source.LastIndexOf("/"));
                    var pattern = source.Substring(source.LastIndexOf("/") + 1);
                    try{
                        Directory.EnumerateFiles(dir, pattern).Any();
                        exists = true;
                    }catch(Exception){
                    }
                }
            } else {
                FileInfo fileinfo = new FileInfo(source);
                exists = fileinfo.Exists;
            }

            if (exists) {
                ManifestFile mf = new ManifestFile();
                mf.Source = source;
                mf.Target = target;
                return mf;
            } else {
                return null;
            }
        }
Exemple #4
0
        static ManifestFile ManifestFileForAssembly(Assembly assembly, string path){
            ManifestFile mf = new ManifestFile();

            AssemblyInfo ainfo = new AssemblyInfo(assembly);

            mf.Source = path;

            string version = "";

            if (string.IsNullOrEmpty(ainfo.TargetFramework)) { 

                if (assembly.ImageRuntimeVersion.StartsWith("v2.0"))
                    version = "/net20";
                if (assembly.ImageRuntimeVersion.StartsWith("v3.5"))
                    version = "/net35";
                if (assembly.ImageRuntimeVersion.StartsWith("v4.0"))
                    version = "/net40";
                if (assembly.ImageRuntimeVersion.StartsWith("v4.5"))
                    version = "/net45";
            }
            else{

                NetPortableProfile npp = new NetPortableProfile("test", new FrameworkName[1]{new FrameworkName(ainfo.TargetFramework)});
                version = "/" + npp.CustomProfileString;
            }

            mf.Target = String.Format("lib{0}", version);

            return mf;
        }
        protected override void ExecuteTask()
        {
            var pb = CreatePackage();

            List<ManifestFile> files = new List<ManifestFile>();
            foreach (var contentSet in ContentSets)
            {
                var target = contentSet.GetTarget();
                foreach (var file in contentSet.FileNames)
                {
                    ManifestFile mf = new ManifestFile();
                    mf.Source = file;
                    mf.Target = Path.Combine(target, Path.GetFileName(file));
                    Log(Level.Verbose, "Added file '{0}' -> '{1}'", file, mf.Target);
                    files.Add(mf);
                }
            }
            pb.PopulateFiles(Project.BaseDirectory, files);

            string savePath = Path.Combine(OutDir.FullName, pb.Id + "-" + pb.Version.ToString() + ".nupkg");
            var saveDir = Directory.GetParent(savePath);
            if (!saveDir.Exists)
                saveDir.Create();
            using (FileStream fs = File.Open(savePath, FileMode.Create, FileAccess.ReadWrite))
                pb.Save(fs);

            Log(Level.Info, "Package created at '{0}'", savePath);
            if (!String.IsNullOrWhiteSpace(Property))
                Properties.Add(Property, savePath);

            if (SymbolsContent != null)
            {
                pb = CreatePackage();

                files = new List<ManifestFile>();
                foreach (var contentSet in SymbolsContent.ContentSets)
                {
                    var target = contentSet.GetTarget();
                    var basePath = contentSet.BaseDirectory;
                    foreach (var file in contentSet.FileNames)
                    {
                        ManifestFile mf = new ManifestFile();
                        mf.Source = file;
                        mf.Target = Path.Combine(target, MakeRelativePath(basePath.FullName + '\\', file));
                        Log(Level.Verbose, "Added file '{0}' -> '{1}' to symbols package.", file, mf.Target);
                        files.Add(mf);
                    }
                }
                pb.PopulateFiles(Project.BaseDirectory, files);

                savePath = Path.Combine(OutDir.FullName, pb.Id + "-" + pb.Version.ToString() + ".symbols.nupkg");
                using (FileStream fs = File.Open(savePath, FileMode.Create, FileAccess.ReadWrite))
                    pb.Save(fs);

                Log(Level.Info, "Symbols package created at '{0}'", savePath);
                if (!String.IsNullOrWhiteSpace(SymbolsContent.Property))
                    Properties.Add(SymbolsContent.Property, savePath);
            }
        }
Exemple #6
0
    private bool CheckAssemblyAndIncludeIfReferenced(Assembly ass)
    {

      if (NuspecDefinition.IsToolsOnly)
        return true;
      string fileName;
      string pbdFileName;
      if (string.IsNullOrEmpty(ass.Location))
      {
        fileName = ass.GetName().Name + ".dll";
        pbdFileName = ass.GetName().Name + ".pbd";
      }
      else
      {
        var assFileInfo = new FileInfo(ass.Location);
        fileName = assFileInfo.Name;
        pbdFileName = assFileInfo.Name.Replace(assFileInfo.Extension, ".pdb");
      }
      var assemblyInBuildFolder = Path.Combine(_outputPath, fileName);
      if (!File.Exists(assemblyInBuildFolder))
        return false;

      if (CheckAssemblyFoundInPackagesFolders(fileName))
      {
        return false;
      }

      var target = _libTargets[_assembly.ImageRuntimeVersion];
      var mf = new ManifestFile
      {
        Source = assemblyInBuildFolder,
        Target = string.Format(@"lib\{0}", target)
      };
      NuspecDefinition.ManifestFiles.Add(mf);

      var pdbFullName = Path.Combine(_outputPath, pbdFileName);
      if (NuspecDefinition.IncludePdb && File.Exists(pdbFullName))
      {
        var pbd = new ManifestFile
        {
          Source = pdbFullName,
          Target = string.Format(@"lib\{0}", target)
        };
        NuspecDefinition.ManifestFiles.Add(pbd);
      }


      return true;
    }