我需要获取特定项目文件引用的 NuGet软件包的列表。我知道 Package Manager控制台中的 private void MergeDocuments()
{
bool docfilechecked = keepworddoc.Checked;
string caseno = casetextboxinput.Value;
string nameno = patentee;
string[] mergeFiles = Directory.GetFiles(directoryrootmerge + caseno + @"\", sequenceCounter + "*.doc*")
.Select(Path.GetFullPath)
.ToArray();
string filename = caseno + @" - " + nameno + " - PoA Form.docx";
string directory = directoryrootmerge + caseno;
string outputFileName = directoryrootmerge + caseno + @"\" + caseno + @" - " + nameno + " - PoA Form.docx";
//string outputFileName2 = directoryrootmerge + caseno + @"\" + caseno + @" - " + nameno + "- PoA Form.pdf";
if (mergeFiles.Length == 1)
{
System.IO.File.Copy(mergeFiles[0], outputFileName, true);
}
else
{
for (int i = 1; i < mergeFiles.Length; i++)
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(mergeFiles[0], true))
{
MainDocumentPart mainPart = myDoc.MainDocumentPart;
string altChunkId = "AltChunkId" + i;
//Append page break
Paragraph para = new Paragraph(new Run((new DocumentFormat.OpenXml.Wordprocessing.Break() { Type = BreakValues.Page })));
mainPart.Document.Body.InsertAfter(para, mainPart.Document.Body.LastChild);
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML, altChunkId);
using (FileStream fileStream = System.IO.File.Open(mergeFiles[i], FileMode.Open))
{
chunk.FeedData(fileStream);
}
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
//new page, if you like it...
//mainPart.Document.Body.AppendChild(new Paragraph(new Run(new DocumentFormat.OpenXml.Wordprocessing.Break() { Type = BreakValues.Page })));
mainPart.Document.Body.InsertAfter(altChunk, mainPart.Document.Body.Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().Last());
mainPart.Document.Save();
myDoc.Close();
System.IO.File.Copy(mergeFiles[0], outputFileName, true);
}
}
}
是这样做的。但是我需要在Visual Studio之外执行此操作。使用 Nuget.Client 或 NuGet.Core 的 C#代码会很有帮助。