如何防止 Visual Studio 2005 的“Clean”错误删除第 3 方二进制文件的命令?

发布于 2024-08-22 08:33:31 字数 578 浏览 3 评论 0原文

我正在开发一个 Sitecore/ASP.NET 项目。今天的某个时候,我无意中点击了解决方案上下文菜单中的“清理”选项。我花了一段时间才弄清楚为什么我的网站被彻底破坏了。结果 Visual Studio 继续从 \bin 目录中删除了几个所需的程序集,这些程序集不属于我的项目。

我怎样才能防止这种情况再次发生?

奇怪的是,它并没有删除所有内容……只是删除了一小部分。它留下了许多我的项目没有直接引用的内容。这让我想知道这个功能究竟应该做什么?我可以设置某种文件标志吗?所有文件均未设置为只读。如果您对详细信息感兴趣,以下内容已被删除:

Sitecore.Analytics.dll
Sitecore.Client.XML
Stimulsoft.Base.dll
Stimulsoft.Report.dll
Stimulsoft.Report.Web.dll
Stimulsoft.Report.WebDesign.dll
Telerik.Web.UI.dll

更新:你知道吗...我想我真正更感兴趣的是为什么 Visual Studio 会保留大部分文件并且只删除这些文件具体的。

I have a Sitecore/ASP.NET projects that I'm developing. Today at some point I inadvertently hit the "Clean" option in the solution context menu. It took me a while to figure out why my site was hopelessly broken. Turns out Visual Studio went ahead and deleted several required assemblies from the \bin dir which are not part of my project.

How can I prevent this from happening again?

The odd thing is that it did NOT delete everything... just a small handful. It left many that are not directly referenced by my project. This makes me wonder exactly what this feature is supposed to do? Is there some sort of file flag I can set? None of the files are set to read-only. If you're interested in details, the following got deleted:

Sitecore.Analytics.dll
Sitecore.Client.XML
Stimulsoft.Base.dll
Stimulsoft.Report.dll
Stimulsoft.Report.Web.dll
Stimulsoft.Report.WebDesign.dll
Telerik.Web.UI.dll

UPDATE: You know what... I guess what I'm really more interested in here is WHY Visual Studio is leaving most of the files and only deleting these specific ones.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

若水般的淡然安静女子 2024-08-29 08:33:31

您的问题的正确答案取决于您如何引用程序集以及如何将它们包含在项目输出中。

项目生成的 binobj 文件夹最好被视为“输出”文件夹;这些文件夹应该只包含项目构建生成的文件。

当您执行项目的清理或重建时,所有中间文件和编译文件都将从这些文件夹中删除。

您应该对这种情况的发生感到满意。

您应该能够随时通过运行构建过程来恢复这些文件夹。如果您直接将文件添加到这些文件夹中,则会破坏这些文件夹的用途,并且意味着您应该重新考虑如何添加这些文件。

引用已编译程序集的首选方法是将它们添加到源文件夹中的某个位置。从那里,它们可以像任何其他文件一样轻松地添加到源代码控制系统中,并且可以由依赖它们的项目引用/复制。在我的工作中,我们有一个“库”文件夹,其中包含解决方案层次结构中的多个项目引用的许多第三方程序集。

尝试使用这样的源代码树,看看它是否适合您:

  • /Projects/My Solution/
  • /Projects/My Solution/Libraries/
  • /Projects/My Solution/Project A/
  • /Projects/My Solution/Project B/

The correct answer to your problem will depend on how you are referencing the assemblies and how you include them in your project output.

The bin and obj folders generated by a project are best considered "output" folders; these folders should only contain files produced by the project build.

When you perform a clean or rebuild of a project, all intermediary and compiled files are deleted from these folders.

You should be comfortable this is happening.

You should be able to restore these folders by running the build process at any time. If you have added files to these folders directly, it breaks the purpose of these folders and means you ought to rethink how you're adding those files.

The preferred way to reference compiled assemblies is to add them somewhere inside your source folders. From there, they can be added to a source control system as easily as any other file and can be referenced/copied by projects which depend on them. In my work, we have a "Libraries" folder which contains numerous third-party assemblies referenced by multiple projects in our solution hierarchy.

Try using a source tree like this and seeing if it works for you:

  • /Projects/My Solution/
  • /Projects/My Solution/Libraries/
  • /Projects/My Solution/Project A/
  • /Projects/My Solution/Project B/
空城旧梦 2024-08-29 08:33:31

我们总是将 AfterBuild 事件添加到包含 Sitecore 的项目文件中。

<Target Name="AfterBuild">
    <CreateItem Include="$(SolutionDir)\Third Party\Sitecore\*.*">
      <Output TaskParameter="Include" ItemName="FilesToArchive" />
    </CreateItem>
    <Copy SourceFiles="@(FilesToArchive)" DestinationFolder="$(TargetDir)\%(FilesToArchive.RecursiveDir)" />
  </Target>

其中 CreateItem Include 是放置 Sitecore 二进制文件的路径。

We always add an AfterBuild event to the project file containing Sitecore.

<Target Name="AfterBuild">
    <CreateItem Include="$(SolutionDir)\Third Party\Sitecore\*.*">
      <Output TaskParameter="Include" ItemName="FilesToArchive" />
    </CreateItem>
    <Copy SourceFiles="@(FilesToArchive)" DestinationFolder="$(TargetDir)\%(FilesToArchive.RecursiveDir)" />
  </Target>

Where the CreateItem Include is the path to where you have placed your Sitecore binaries.

丑疤怪 2024-08-29 08:33:31

将 dll 放在不同的目录中。您可能不希望它们成为项目的一部分。引用新目录中的 dll。编译时,dll 将被复制到 bin 目录中。

我处理很多项目,并在项目的根目录下保留一个 bin 目录来存储第 3 方 dll,正是出于这个原因。

示例目录结构:

MyProjects
 - bin
   - 3rdParty.dll
 - Project1
 - Project2
 - ProjectN

这允许所有项目都有一个众所周知的 3rd 方 dll 参考位置,而无需将 dll 复制到每个项目中。

如果您在一个团队中工作,那么您应该就代码的标准目录结构达成一致。除此之外,这将为您节省很多麻烦。

Put the dlls in a different directory. You will probably not want them as part of the project. Reference the dlls from the new directory. When you compile the dlls will be copied to the bin directory.

I work with lots of projects and keep a bin directory at the root of my projects to store 3rd party dlls for exactly this reason.

Example directory structure:

MyProjects
 - bin
   - 3rdParty.dll
 - Project1
 - Project2
 - ProjectN

This allows all the projects to have a well-known reference location for 3rd party dlls without having to copy the dll into each project.

If you are working on a team you should all agree on a standard directory structure for your code. This will save you lots of headaches beyond just this.

冷默言语 2024-08-29 08:33:31

对于 Sitecore,只需确保设置引用的属性(Sitecore.Kernel、Sitecore.Client 等):
“复制本地”= false。

In case of Sitecore, just make sure to set the property of the reference(Sitecore.Kernel, Sitecore.Client, etc):
'Copy Local' = false.

终难愈 2024-08-29 08:33:31

我相信,如果您将这些文件放在 bin 以外的子目录中,Visual Studio 不会删除它们。您仍然可以将新的子目录作为部署的一部分。

I believe that if you put these files in a subdirectory other than bin, Visual Studio won't remove them. You can still make the new subdirectory part of your deployment.

猫性小仙女 2024-08-29 08:33:31

好吧,我将继续回答我自己的问题,因为这似乎是迄今为止最简单的答案。我将相关程序集标记为只读。现在他们没有被清理。

仍然想知道为什么大多数其他人没有被删除。

Well, I'm going to go ahead and answer my own question, since it seems like the simplest answer so far. I marked the assemblies in question as Read-only. Now they don't get cleaned.

Still wondering why most of the others don't get deleted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文