简体   繁体   English

有没有办法重新创建 packages.config 文件?

[英]Is there any way to recreate packages.config file?

I accidentally missed to upload to source control NuGet packages.config file and it got deleted somehow:(我不小心错过了上传到源代码管理 NuGet packages.config 文件,它以某种方式被删除了:(

Is there any way to recreate it?有没有办法重新创建它?

An easier way will be just go to Nuget and reinstall the packages. 更简单的方法是去Nuget并重新安装软件包。 It will create the package.config file 它将创建package.config文件

It's kind of tricky to do it in an automated way. 以自动方式执行它有点棘手。 Easiest is to simply re-create the packages.config manually, added entries for each directory in the packages dir. 最简单的方法是手动重新创建packages.config ,为packages目录中的每个目录添加条目。 For example, I have the following dirs in my packages directory: 例如,我在packages目录中有以下dirs:

Microsoft.Bcl.1.1.3
Microsoft.Bcl.Async.1.0.16
Microsoft.Net.Http.2.2.15
Newtonsoft.Json.5.0.8
repositories.config
WindowsAzure.MobileServices.1.0.2
WPtoolkit.4.2013.08.16

If I were to re-create the packages.config, I could simply take the directory name, separate the version number and create a line for each package like: 如果我要重新创建packages.config,我可以简单地获取目录名称,分隔版本号并为每个包创建一行,如:

  <package id="Microsoft.Bcl" version="1.1.3" targetFramework="wp71" />

adding the targetFramework attribute to whatever target that project was using. targetFramework属性添加到项目正在使用的任何目标。

Then wrap all of those <package> elements with 然后用所有这些<package>元素<package>

<?xml version="1.0" encoding="utf-8"?>
<packages>
 <!--...-->
</packages>

Resulting in something like this: 结果是这样的:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Bcl" version="1.1.3" targetFramework="wp71" />
  <package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="wp71" />
  <package id="Microsoft.Net.Http" version="2.2.15" targetFramework="wp71" />
  <package id="Newtonsoft.Json" version="5.0.8" targetFramework="wp71" />
  <package id="WindowsAzure.MobileServices" version="1.0.2" targetFramework="wp71" />
  <package id="WPtoolkit" version="4.2013.08.16" targetFramework="wp71" />
</packages>

Why not use the console-manager?为什么不使用控制台管理器?

For restoring you van both use the NuGet package manager as the console.要恢复您的货车,请使用 NuGet package 管理器作为控制台。

Restore packages using Package Restore 使用 Package 恢复包

Some things only work with the console??(?correct?)有些东西只适用于控制台??(?正确?)

Micrsoft Docs: How to reinstall and update packages Micrsoft Docs:如何重新安装和更新软件包

Ref.: Why, when and how to reinstall NuGet packages after upgrading a project参考: 为什么,何时以及如何在升级项目后重新安装 NuGet 包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM