[英]What is the difference between Visual Studio Package and VSIX Project types?
[英]configure visual studio with nuget package, VSIX automatically
我必須在我的視覺工作室中配置nugets和VSIX。 現在,我們通過在“工具”->“選項”->“環境/工具”->“選項”->“ Nuget軟件包管理器”下添加軟件包源來手動執行此操作。
當我們在Visual Studio中打開“工具”->“選項”時,我需要自動填充nuget和VSIX的提要/ URL,以便用戶應僅選擇相應的提要並進行安裝,以消除添加用於安裝nugets /的url的手動開銷VSIX。
謝謝。
可以以編程方式為所需的nuget提要配置Nuget畫廊。 我們通過編寫一個自定義控件來做到這一點。 在我們的系統中,“ AppData”文件夾下有一個名為Nuget.config的文件。
在此文件中,列出了所有Nuget字段,因此用戶可以在Visual Studio->工具->選項->環境/工具->選項-> Nuget軟件包管理器中看到那些Nuget提要。
要添加您的Nuget Feed,您只需要修改Nuget.Config文件並將其添加到其中即可。 下面是代碼:
[CustomAction]
public static ActionResult ConfigAdeptNuGetFeed(Session session)
{
session.Log("*** Begin ConfigAdeptNuGetFeed ***");
var result = ActionResult.Failure;
if (File.Exists(XDocPath))
{
session.Log("Nuget.config was found in the %appdata% folder.");
try
{
var xDoc = new XmlDocument();
xDoc.Load(XDocPath);
var baseNode = xDoc.DocumentElement;
if (baseNode != null)
{
session.Log($"{baseNode.Name} has {baseNode.ChildNodes.Count} child elements.");
session.Log($"XML before install: {baseNode.OuterXml}");
if (baseNode.ChildNodes.Count >= 2)
{
//Checks for the AdeptNugetfeed.
var node =
baseNode.SelectSingleNode($"//add[@value='{AdeptInstaller.AdeptNuGetFeedPath}']");
//AdeptFeed not found, adding it.
if (node == null)
{
session.Log("Adept Feed not present. Adding it now.");
var packageNode = xDoc.GetElementsByTagName("packageSources")[0];
var newElement = xDoc.CreateElement("add");
var xAttribute = xDoc.CreateAttribute("key");
xAttribute.Value = "AdeptNugetFeed";
var xAttributeVal = xDoc.CreateAttribute("value");
xAttributeVal.Value = AdeptInstaller.AdeptNuGetFeedPath;
newElement.Attributes.Append(xAttribute);
newElement.Attributes.Append(xAttributeVal);
packageNode.AppendChild(newElement);
}
else
{
session.Log("Adept feed is already present. Nothing to do.");
}
}
else
{
session.Log($"{baseNode.Name} is empty.");
baseNode.InnerXml = AdeptInstaller.NuGetFullConfig;
}
xDoc.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Nuget", "Nuget.config"));
session.Log($"XML after install: {baseNode.OuterXml}");
}
else
{
session.Log("NuGet.config file is invalid... abbending.");
throw new XmlException("XML issue with the reading of the nuget.config file.");
}
result = ActionResult.Success;
}
catch (Exception exc)
{
session.Log(exc.ToString());
result = ActionResult.Failure;
}
}
else
{
Console.WriteLine(AdeptInstaller.Nuget_config_file_not_found);
result = ActionResult.Failure;
}
return result;
}
更好的方法是運行powershell comand Register-PackageSource例如
Register-PackageSource -Name "My package source" -Location "C:\MyNugetPackages" -ProviderName "NuGet"
這會將軟件包源也添加到Visual Studio設置中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.