visual-studio 如何在与 web 项目相同的目录中创建 Visual Studio 解决方案文件 (.sln)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/213719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:47:30  来源:igfitidea点击:

How do you create a Visual Studio Solution File (.sln) in the same directory as the web project?

visual-studiovisual-studio-2008visual-studio-2005projects-and-solutions

提问by Brian Boatright

I'm using VisualSVN client and server and one of the requirements for web projects to work as expected is to have the .sln in the same directory (root) as the other files.

我正在使用 VisualSVN 客户端和服务器,Web 项目按预期工作的要求之一是将 .sln 与其他文件位于同一目录(根)中。

I thought it was as simple as removing all the extra parent paths ../ and other relative paths and saving it. However when I try to open it just locks up Visual Studio.

我认为这就像删除所有额外的父路径 ../ 和其他相对路径并保存它一样简单。但是,当我尝试打开它时,它只会锁定 Visual Studio。

Is there a standard way to create this type of solution file or a solution file tool to help make sure it is valid? Or am I just missing something very obvious?

是否有标准方法可以创建此类解决方案文件或解决方案文件工具来帮助确保其有效?还是我只是遗漏了一些非常明显的东西?

/
/MyWebsite.org.sln
/Images
/App_Data
/default.aspx
/default.aspx.cs

So apparently the trick, at least the one I was seeking is that you must use ..\MyWebsite.org or whatever the folder that contains the website files.

显然,至少我正在寻找的技巧是您必须使用 ..\MyWebsite.org 或任何包含网站文件的文件夹。

[EDIT] What I learned and my final .sln file for this particular project:

[编辑] 我学到了什么,以及我针对这个特定项目的最终 .sln 文件:

Here is the final Solution file that allowed me to open the website and have the .sln in the root of the web folder.

这是最终的解决方案文件,它允许我打开网站并将 .sln 放在 web 文件夹的根目录中。

Project("{E24C65DC-7377-472B-9ABA-BCSG3B73C61A}") = "MyWebsite.org", "\", "{F8F4E96F-40BF-4374-B8BA-968D0SGG4A9E}"
    ProjectSection(WebsiteProperties) = preProject
        TargetFramework = "3.5"
        Debug.AspNetCompiler.VirtualPath = "/MyWebsite.org"
        Debug.AspNetCompiler.PhysicalPath = "..\MyWebsite.org\"
        Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\MyWebsite.org\"
        Debug.AspNetCompiler.Updateable = "true"
        Debug.AspNetCompiler.ForceOverwrite = "true"
        Debug.AspNetCompiler.FixedNames = "false"
        Debug.AspNetCompiler.Debug = "True"
        Release.AspNetCompiler.VirtualPath = "/MyWebsite.org"
        Release.AspNetCompiler.PhysicalPath = "..\MyWebsite.org\"
        Release.AspNetCompiler.TargetPath = "PrecompiledWeb\MyWebsite.org\"
        Release.AspNetCompiler.Updateable = "true"
        Release.AspNetCompiler.ForceOverwrite = "true"
        Release.AspNetCompiler.FixedNames = "false"
        Release.AspNetCompiler.Debug = "False"
        VWDPort = "1603"
        VWDDynamicPort = "false"
        VWDVirtualPath = "/"
    EndProjectSection
EndProject

采纳答案by Mitchel Sellers

THe other option is when you create the project simply uncheck the default box for "create directory for solution"

另一个选项是当您创建项目时,只需取消选中“为解决方案创建目录”的默认框

回答by AJ.

Generally what I do is start with a Blank Solution, which is under "Other Project Types-->Visual Studio Solutions" in the New Project dialog. Then, add the website and whatever other projects you need to the solution.

通常我所做的是从一个空白解决方案开始,它位于“新建项目”对话框中的“其他项目类型--> Visual Studio 解决方案”下。然后,将网站和您需要的任何其他项目添加到解决方案中。

回答by Jeremy B.

the following steps should work.

以下步骤应该有效。

  1. make a blank solution, nothing in it.
  2. Move the solution to where you want the web project to live.
  3. Open the solution.
  4. Create the web project in the desired area.
  1. 做一个空白的解决方案,里面什么都没有。
  2. 将解决方案移至您希望 Web 项目所在的位置。
  3. 打开解决方案。
  4. 在所需区域创建 Web 项目。

I often do this sort of moving around so that projects will sit nicely in svn. Don't forget to svn:ignore the *.suo files.

我经常做这种移动,以便项目在 svn 中很好地放置。不要忘记 svn:ignore *.suo 文件。

回答by pmulimani

Goto Tools->Options->Projects and Solutions then check the Always show solution.

转到工具-> 选项-> 项目和解决方案,然后选中始终显示解决方案。

回答by tsilb

Create the solution, close it, put the files where you want them, and edit the sln.

创建解决方案,关闭它,将文件放在您想要的位置,然后编辑 sln.conf 文件。

回答by StanM

I couldn't find a solution file for my project. I was able to run the project on one machine without a .sln in the project. The reason it worked on the machine I created it on was that that I keep my VS projects under C:\Dev\Projects but Visual Studio kept its .sln file c:\users\xyz\documents\VisualStudio2015\projects directory. When I moved the files to a new computer the .sln wasn't in the same directory. I just found the project set up in the old computer in the c:\users\xyz\documents\VisualStudio2015\projects directory and moved that to my new computer. I believe I could have avoided this by changing the Tools->Options->Projects and Solutions section

我找不到我的项目的解决方案文件。我能够在一台机器上运行该项目,而项目中没有 .sln。它在我创建它的机器上工作的原因是我将我的 VS 项目保存在 C:\Dev\Projects 下,但 Visual Studio 将其 .sln 文件保存在 c:\users\xyz\documents\VisualStudio2015\projects 目录下。当我将文件移动到新计算机时,.sln 不在同一目录中。我刚刚在 c:\users\xyz\documents\VisualStudio2015\projects 目录中的旧计算机中找到了该项目,并将其移至我的新计算机。我相信我可以通过更改工具->选项->项目和解决方案部分来避免这种情况

回答by parwaze

Re-create a project from existing files in asp.net

从 asp.net 中的现有文件重新创建项目

Copy the existing files to a location eg. F:\Copy_webSite

将现有文件复制到某个位置,例如。F:\Copy_webSite

Open visual studio > file > new website.

打开 Visual Studio > 文件 > 新网站。

[enter image description here][1] Select the folder where you copied the files [enter image description here][2]

[在此处输入图像描述][1] 选择您复制文件的文件夹 [在此处输入图像描述][2]

You will be prompted “web site already existed” select “open the existing web site”

提示“网站已经存在”选择“打开现有网站”

System will create the .sln file in folder C:\Users\user\Documents\Visual Studio 2005\Projects\WebSite [enter image description here][3]

系统将在文件夹 C:\Users\user\Documents\Visual Studio 2005\Projects\WebSite [在此处输入图像描述][3] 中创建 .sln 文件

System will open the current project. You can also copy the the .sln file in the same folder of the current project. It will open the project in the folder

系统将打开当前项目。您也可以将 .sln 文件复制到当前项目的同一文件夹中。它将打开文件夹中的项目

回答by Kickass

Just had to do this after a bad OS install resulted in partition damage and had to recover the data. Months later I needed to change code but the .sln file was gone.

在错误的操作系统安装导致分区损坏并不得不恢复数据后,只需执行此操作。几个月后,我需要更改代码,但 .sln 文件不见了。

Using Visual Studio 2015 Go to New -> Website -> Select the root directory of the website in need of a new .sln file -> Next -> It will ask to create new site in directory or open the website in directory, obviously select the latter. Opened no problem with zero errors and it was even fast at doing it -> Save project and you're good to go.

使用 Visual Studio 2015 去新建 -> 网站 -> 选择需要新 .sln 文件的网站的根目录 -> 下一步 -> 它会要求在目录中创建新站点或在目录中打开网站,显然选择后者。以零错误打开没有问题,它甚至做得很快 - >保存项目,你很高兴。

Occam's Razor!

奥卡姆剃刀!