简体   繁体   English

为什么visual studio会在Azure DevOps签入时排除BIN和OBJ文件夹

[英]Why does visual studio exclude BIN and OBJ folders at Azure DevOps checkin

I want to know what is the generic way to check-in code on Azure DevOps from Visual Studio or Git-Bash that has been coded in Visual Studio. 我想知道在Visual Studio中使用Visual Studio或Git-Bash在Azure DevOps上签入代码的通用方法是什么。 The problem that occurs is the bin folder contains many third party dll's which are kept in the source before building the project. 发生的问题是bin文件夹包含许多第三方dll,它们在构建项目之前保留在源中。 Those third party dll's are necessary to project. 投射这些第三方dll是必要的。 However after check-in to Azure DevOps the bin and obj are not present. 但是在登录Azure DevOps后,bin和obj不存在。 This happens due to .gitignore and .gitattribute files. 这是由.gitignore和.gitattribute文件引起的。 I have deleted both the files and checked in the bin folder as of now. 我已经删除了这两个文件并检查了bin文件夹。 What is the purpose of these two files. 这两个文件的目的是什么。 Can someone please suggest a way to resolve. 有人可以建议一种解决方法。

排除

.gitignore is designed to exclude things from source control. .gitignore旨在从源代码管理中排除内容。 For example if you had a file with your connection string to a database in your development folder you would not want your password checked into source control. 例如,如果您的文件中包含连接字符串到开发文件夹中的数据库,则不希望将密码签入源代码管理中。 Checking in binaries into your repository is a bad practice. 将二进制文件签入存储库是一种不好的做法。 You should be using dependency management system (like Nuget, Chocolately, Maven, npm, etc) to specify your dependencies and download them. 您应该使用依赖关系管理系统(如Nuget,Chocolately,Maven,npm等)来指定依赖关系并下载它们。 The way you are doing it now you would check in multiple copies of them into multiple projects and not be able to management them in one place. 您现在的方式就是将它们的多个副本签入多个项目,而不是在一个地方管理它们。 Proper dependency management likely is the reason the default versions of .gitignore exclude certain folders. 正确的依赖关系管理可能是.gitignore的默认版本排除某些文件夹的原因。 You also want to regenerate all the contents of the obj folder. 您还想重新生成obj文件夹的所有内容。 If you have old copies timestamps get odd. 如果你有旧版本,时间戳会变得奇怪。 A clean build every time means starting from a fresh copy without any compiled artifacts. 每次干净的构建意味着从没有任何编译工件的新副本开始。

.gitignore file specifies the untracked files. .gitignore文件指定未跟踪的文件。 .gitattributes defines attributes per path. .gitattributes定义每个路径的属性。 They are configuration files of Git. 它们是Git的配置文件。

In Visual Studio, the bin and obj folders are used to store the output generated by compilers (see here ). 在Visual Studio中,bin和obj文件夹用于存储编译器生成的输出(请参见此处 )。 As these output files are generated by compilers, you don't want to track them in the source control. 由于这些输出文件是由编译器生成的,因此您不希望在源代码管理中跟踪它们。

If your project need to reference to some 3rd party dlls, the best approach is to reference to them as Nuget packages if there are Nuget packages available for the dlls. 如果您的项目需要引用某些第三方dll,最好的方法是将它们作为Nuget包引用,如果有可用于dll的Nuget包。 If not, you can put them in a folder other than bin or obj so they can be tracked in Git. 如果没有,你可以将它们放在bin或obj以外的文件夹中,这样就可以在Git中跟踪它们。 You should not change .gitignore to track bin or obj folders. 您不应将.gitignore更改为跟踪bin或obj文件夹。

To pile on: even if you do want to check in your bin folder (and, as others have mentioned, you do not), do not do this by removing the .gitignore and .gitattributes files. 要打开:即使您确实要检查bin文件夹(并且,正如其他人提到的那样,您没有),请不要通过删除.gitignore.gitattributes文件来执行此操作。

.gitignore contains a list of files that should not be added to your repository. .gitignore包含了应该添加到您的库文件的列表。 These are files that should not be shared with the team like local configuration data. 这些文件不应与团队共享,如本地配置数据。 If you commit the SQLite data in the .vs directory you will get countless conflicts and be unable to pull because Visual Studio will have that file locked. 如果您在.vs目录中提交SQLite数据,您将获得无数冲突并且无法拉动,因为Visual Studio将锁定该文件。

.gitattributes contains a set of configurations, especially for line endings. .gitattributes包含一组配置,尤其适用于行结尾。 This must exist in the repository for all developers to agree on the setup, or you will get conflicts around whitespace. 这必须存在于存储库中,供所有开发人员就设置达成一致,否则您将遇到有关空白的冲突。

If you really must (and you mustn't) check files in to your bin directory, restore your .gitignore and .gitattributes . 如果您确实必须(并且必须)检查bin目录中的文件,请恢复.gitignore.gitattributes Then explicitly list them in the .gitignore with a negation pattern: 然后使用否定模式在.gitignore明确列出它们:

!bin/foo.dll

But - as others have commented - this is still a bad idea. 但是 - 正如其他人所评论的那样 - 这仍然是一个坏主意。

As most of them already provided great answers. 因为大多数人已经提供了很好的答案。 I'd provide you with some ideas of how to handle the 3rd party DLL(Assemblies) 我将为您提供有关如何处理第三方DLL(程序集)的一些想法

Please remember that ideal/best way of using 3rd part libraries is through NuGet Feed/Packages 请记住,使用第三部分库的理想/最佳方式是通过NuGet Feed / Packages

For some case, those DLL's wouldn't be available in Nuget.org. 在某些情况下,这些DLL在Nuget.org中不可用。 In such case, you can follow this steps to add the references in your project. 在这种情况下,您可以按照以下步骤在项目中添加引用。

  1. Create a folder within your project called lib 在项目中创建一个名为lib的文件夹

在此输入图像描述

  1. Add the DLL in that folder 在该文件夹中添加DLL

在此输入图像描述

  1. Right Click the DLL->Go to Properties , then Change the BuildAction to None and Copy to Output Directory to Do not copy for the DLL 右键单击DLL->转到Properties ,然后将BuildAction更改为NoneCopy to Output DirectoryDo not copy DLL

在此输入图像描述

  1. Finally, Add the References from the lib folder 最后,从lib文件夹添加引用

在此输入图像描述

So when you are checking the projects into any version control the lib folder will also get check-in and during the build, the references will also get from the lib folder. 因此,当您将项目检入任何版本控件时,lib文件夹也将获得签入,在构建期间,引用也将从lib文件夹中获取。

Remember again don't use bin/obj folder to refer your DLL's and Don't ever check-in bin and Obj folder. 再次记住,不要使用bin / obj文件夹来引用你的DLL,也不要使用bin-obj文件夹。 As those folders will be autogenerated during the build itself. 因为这些文件夹将在构建期间自动生成。

The bin folder is definetely the wrong place to store 3rd party dlls. bin文件夹定义为存储第三方dll的错误位置。 Store them somewhere else and copy them to the bin folder during building or if available use NuGet packages. 将它们存储在其他地方并在构建期间将它们复制到bin文件夹,或者如果可用则使用NuGet包。 It is a widely used standard procedure to exclude the bin folders from checking into source control. 这是一个广泛使用的标准过程,用于将bin文件夹排除在检查源控件之外。 Also if you decide to do a cleanup of your solution, your bin folders will get emptied out and your 3rd party dlls will be gone. 此外,如果您决定清理您的解决方案,您的bin文件夹将被清空,您的第三方dll将会消失。

Another point, since your posting a question with the azure-devops tag, azure-devops provides a powerful building and testing pipeline. 另一点,由于您使用azure-devops标签发布问题,azure-devops提供了强大的构建和测试管道。 This means you can check in your code and the hosted build server (standard scenario, IF you set it up that way) will pull your code from source control and do a build, run some tests and if everything is OK zip your binaries and put them somewhere where you can dowload them. 这意味着您可以检入您的代码和托管构建服务器(标准方案, 如果您按照这种方式设置)将从源代码控制中提取代码并执行构建,运行一些测试,如果一切正常,则压缩您的二进制文件并放入他们在某个你可以下载它们的地方。 Now what happens to your own dlls in bin that you have checked in? 现在,您已经签入的垃圾箱中的垃圾箱会发生什么? They will get overwritten when the server builds your code. 当服务器构建代码时,它们将被覆盖。 So why check them in in the first place? 那么为什么要先检查它们呢? If the server does a cleanup (which it will not necessarrily do) then your 3rd party dlls will be missing. 如果服务器进行了清理(它不一定会这样做),那么你的第三方dll将会丢失。

暂无
暂无

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

相关问题 当我使用管道在azure devop上构建csproj文件时,为什么没有创建bin和obj文件夹? - Why are bin and obj folders not getting created when I am building a csproj file on azure devops using pipeline? Visual Studio 无法正确清理 obj 文件夹 - Visual Studio doesn't clean obj folders properly 为什么Visual Studio 2017和.net Core 2.1中的Azure开发人员之间的发布输出有所不同? - Why difference in publish output between visual studio 2017 and azure devops in .net core 2.1? MS Visual Studio:如何从发布中排除某些项目文件夹? - MS Visual Studio: How to exclude certain Project Folders from publishing? .NET c#:为什么Visual Studio希望我将文件放入c:\\…\\ myConsoleApplication \\ bin \\ Debug - .NET c#: Why does Visual studio expect me to put my files in c:\…\myConsoleApplication\bin\Debug Visual Studio 构建失败:无法将 exe 文件从 obj\debug 复制到 bin\debug - Visual Studio build fails: unable to copy exe-file from obj\debug to bin\debug Dispose()导致可怕的Visual Studio“无法将文件从obj复制到bin'错误? - Dispose() causes dreaded Visual Studio "Unable to copy file from obj to bin' error? 我怎么能忽略 git 存储库中的 bin 和 obj 文件夹? - How could I ignore bin and obj folders from git repository? 如何从Visual Studio 2012检测到的更改列表中排除某些文件夹? - How to exclude certain folders from Visual Studio 2012 detected changes list? 如何在 Azure DevOps 管道中运行 MongoDB 服务器和 Visual Studio 单元测试? - How can I run MongoDB server and visual studio unit tests in an Azure DevOps pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM