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.
我有一个我正在开发的Sitecore / ASP.NET项目。今天在某些时候我无意中点击了解决方案上下文菜单中的“清理”选项。我花了一段时间才弄清楚为什么我的网站被无可救药地打破了。事实证明Visual Studio继续并从\ bin目录中删除了几个不属于我的项目的必需程序集。
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
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.
更新:你知道吗...我想我真正感兴趣的是为什么Visual Studio会丢弃大部分文件而只删除这些特定的文件。
6 个解决方案
#1
8
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.
项目生成的bin和obj文件夹最好被视为“输出”文件夹;这些文件夹应该只包含项目构建生成的文件。
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.
引用已编译程序集的首选方法是将它们添加到源文件夹中的某个位置。从那里,它们可以像任何其他文件一样轻松地添加到源控制系统中,并且可以由依赖于它们的项目引用/复制。在我的工作中,我们有一个“Libraries”文件夹,其中包含我们的解决方案层次结构中由多个项目引用的众多第三方程序集。
Try using a source tree like this and seeing if it works for you:
尝试使用这样的源代码树,看看它是否适合您:
- /Projects/My Solution/
- / Projects /我的解决方案/
- /Projects/My Solution/Libraries/
- / Projects / My Solution / Libraries /
- /Projects/My Solution/Project A/
- / Projects /我的解决方案/项目A /
- /Projects/My Solution/Project B/
- / Projects / My Solution / Project B /
#2
5
We always add an AfterBuild event to the project file containing Sitecore.
我们总是将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>
Where the CreateItem Include is the path to where you have placed your Sitecore binaries.
CreateItem Include是放置Sitecore二进制文件的路径。
#3
5
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.
将dll放在不同的目录中。您可能不希望它们作为项目的一部分。引用新目录中的dll。编译时,dll会被复制到bin目录中。
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.
我正在处理许多项目并在我的项目的根目录中保留一个bin目录来存储第三方dll,正是出于这个原因。
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.
这允许所有项目都具有第三方dll的着名参考位置,而无需将dll复制到每个项目中。
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.
如果您正在组建团队,那么您应该就代码的标准目录结构达成一致。除此之外,这将为您节省许多麻烦。
#4
4
In case of Sitecore, just make sure to set the property of the reference(Sitecore.Kernel, Sitecore.Client, etc): 'Copy Local' = false.
如果是Sitecore,只需确保设置引用的属性(Sitecore.Kernel,Sitecore.Client等):'Copy Local'= false。
#5
1
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.
我相信如果您将这些文件放在bin之外的子目录中,Visual Studio将不会删除它们。您仍然可以将新子目录作为部署的一部分。
#6
0
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.
仍然想知道为什么大多数其他人不会被删除。
#1
8
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.
项目生成的bin和obj文件夹最好被视为“输出”文件夹;这些文件夹应该只包含项目构建生成的文件。
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.
引用已编译程序集的首选方法是将它们添加到源文件夹中的某个位置。从那里,它们可以像任何其他文件一样轻松地添加到源控制系统中,并且可以由依赖于它们的项目引用/复制。在我的工作中,我们有一个“Libraries”文件夹,其中包含我们的解决方案层次结构中由多个项目引用的众多第三方程序集。
Try using a source tree like this and seeing if it works for you:
尝试使用这样的源代码树,看看它是否适合您:
- /Projects/My Solution/
- / Projects /我的解决方案/
- /Projects/My Solution/Libraries/
- / Projects / My Solution / Libraries /
- /Projects/My Solution/Project A/
- / Projects /我的解决方案/项目A /
- /Projects/My Solution/Project B/
- / Projects / My Solution / Project B /
#2
5
We always add an AfterBuild event to the project file containing Sitecore.
我们总是将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>
Where the CreateItem Include is the path to where you have placed your Sitecore binaries.
CreateItem Include是放置Sitecore二进制文件的路径。
#3
5
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.
将dll放在不同的目录中。您可能不希望它们作为项目的一部分。引用新目录中的dll。编译时,dll会被复制到bin目录中。
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.
我正在处理许多项目并在我的项目的根目录中保留一个bin目录来存储第三方dll,正是出于这个原因。
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.
这允许所有项目都具有第三方dll的着名参考位置,而无需将dll复制到每个项目中。
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.
如果您正在组建团队,那么您应该就代码的标准目录结构达成一致。除此之外,这将为您节省许多麻烦。
#4
4
In case of Sitecore, just make sure to set the property of the reference(Sitecore.Kernel, Sitecore.Client, etc): 'Copy Local' = false.
如果是Sitecore,只需确保设置引用的属性(Sitecore.Kernel,Sitecore.Client等):'Copy Local'= false。
#5
1
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.
我相信如果您将这些文件放在bin之外的子目录中,Visual Studio将不会删除它们。您仍然可以将新子目录作为部署的一部分。
#6
0
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.
仍然想知道为什么大多数其他人不会被删除。