简体   繁体   English

Visual Studio / IIS Express间歇性错误

[英]Visual Studio/IIS Express Intermittent Bugs

I've been having problems with IIS Express for the past few years since we stopped using regular IIS in our projects. 自从我们在项目中停止使用常规IIS以来,过去几年我一直遇到IIS Express问题。 We typically have solutions that have a web service and some kind of client(web, desktop, or both). 我们通常拥有具有Web服务和某种客户端(Web,桌面或两者)的解决方案。 When I run the client about 1 in every 10 times, I will get an error about not finding localhost:blahblah or not being able to load an assembly. 当我每10次运行客户端大约1次时,我会收到一个关于找不到localhost:blahblah或者无法加载程序集的错误。 A full rebuild always fixes this problem. 完全重建始终可以解决此问题。 HOWEVER, this is something that I have dealt with in VS2013 and VS2015 along with my coworkers. 但是,这是我在VS2013和VS2015以及我的同事处理过的事情。 I have come up with a workaround where I added a Pre-build event to delete the bin folder of the web service and do and msbuild on it. 我提出了一个解决方法,我添加了一个预构建事件来删除Web服务的bin文件夹,并在其上执行和msbuild。 This works great on my machine. 这在我的机器上运行良好。 However, I don't know a way to write it where it works on our build server or on other peoples machines. 但是,我不知道如何将它写在我们的构建服务器或其他人机器上。 The Pre-build events get checked into source control as part of the cs.proj file so I need a generic solution if I go that route. 预构建事件作为cs.proj文件的一部分被检入源代码控制中,所以如果我走这条路线,我需要一个通用的解决方案。 Here is my Pre-build script: 这是我的预构建脚本:

DEL /Q "C:\TFS\Enterprise Data Management\Vendor\Dev-Phase2US\WcfService\bin\*.*"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "C:\TFS\Enterprise Data Management\Vendor\Dev-Phase2US\WcfService\WcfService.csproj"

Has anyone else had similar problems? 还有其他人有类似的问题吗? Any good solutions or workarounds? 有什么好的解决方案或解决方法吗?

In answer to the question being asked, to use "generic" paths, use the "Macros" offered in Visual Studio (technically, MSBuild Properties). 在回答被问到的问题时,要使用“通用”路径,请使用Visual Studio中提供的“宏”(技术上,MSBuild属性)。 Assuming the WcfService folder is in the same solution, 假设WcfService文件夹在同一个解决方案中,

DEL /Q "$(SolutionDir)\WcfService\bin\*.*"

Or if it's in some path relative to the project, 或者,如果它在某个相对于项目的路径中,

DEL /Q "$(ProjectDir)..\..\..\WcfService\bin\*.*"

Note that using Pre-Build events for this is pretty bad practice though. 请注意,使用Pre-Build事件是非常糟糕的做法。 It's better to use the Clean task in the project, eg by adding this to your .csproj (under the root element, eg before </Project> ): 最好在项目中使用Clean任务,例如将其添加到.csproj(在根元素下,例如</Project>之前):

  <Target Name="CleanWcfProject" BeforeTargets="PrepareForBuild">
    <MSBuild Projects="$(SolutionDir)\WcfService\WcfService.csproj" Targets="Clean" Properties="Configuration=$(Configuration);Platform=$(Platform)" />
  </Target>

I'm not sure why you're running MSBuild on the WcfService.csproj project either, since you could simply add it as a project reference (right-click > Add Reference > Solution), which would cause MSBuild to automatically build the project upon seeing that its outputs are cleared. 我不确定你为什么在WcfService.csproj项目上运行MSBuild,因为你可以简单地将它添加为项目引用(右键单击>添加引用>解决方案),这将导致MSBuild自动构建项目看到它的输出被清除了。

If your dependent project is in another Solution 如果您的依赖项目在另一个解决方案中

If this is the case, then the Clean should work with a relative path, but adding a ProjectReference may not be desirable/possible (you can still add the dependency to your solution, even if it's in another solution, but often this isn't possible/feasible because of lots of other dependencies). 如果是这种情况,那么Clean应该使用相对路径,但添加ProjectReference可能不是理想/可能的(您仍然可以将依赖项添加到您的解决方案中,即使它在另一个解决方案中,但通常不是由于许多其他依赖性而可能/可行)。

If so, then simply add the build target as well, 如果是这样,那么只需添加构建目标,

  <Target Name="CleanWcfProject" BeforeTargets="PrepareForBuild">
    <MSBuild Projects="$(ProjectDir)..\..\..\WcfService\WcfService.csproj" Targets="Clean;Build" Properties="Configuration=$(Configuration);Platform=$(Platform)" />

  </Target>

Many thanks to Al-Muhandis for getting me on the right track for this. 非常感谢Al-Muhandis让我走上正轨。 In summary, a Rebuild of the WCF Service project fixes my problem 100% of the time. 总之,WCF服务项目的重建在100%的时间内解决了我的问题。 The pre-build event in my initial question was a very hacky way of doing this. 我最初的问题中的预构建事件是一种非常黑客的方式。 A simple Clean isn't enough as I get this error with just a Clean: 一个简单的清洁是不够的,因为我只用一个清洁得到这个错误:

The requested service, ' http://localhost:53934/EdmVendService/EdmVendor.svc ' could not be activated. 无法激活所请求的服务“ http:// localhost:53934 / EdmVendService / EdmVendor.svc ”。 See the server's diagnostic trace logs for more information. 有关更多信息,请参阅服务器的诊断跟踪日志。

My final solution was to add this block of XML to the csproj file. 我的最终解决方案是将这个XML块添加到csproj文件中。 I just used notepad to edit it. 我只是用记事本来编辑它。

<Target Name="RebuildWcfProject" BeforeTargets="PrepareForBuild">
  <MSBuild Projects="$(SolutionDir)\WcfService\WcfService.csproj" Targets="Rebuild" Properties="Configuration=$(Configuration);Platform=$(Platform)" />
</Target>

Here is the bottom of the csproj file after my change. 这是我改变后的csproj文件的底部。

在此输入图像描述

Hope this may be of help to someone else. 希望这对其他人有帮助。

Can you try this alternative settings for your project. 您可以为项目尝试此替代设置吗? Right Click on your web project. 右键单击您的Web项目。 Select Properties and then Select the Web tab. 选择“属性”,然后选择“Web”选项卡。 Configure your Visual Studio as below. 如下配置Visual Studio。

在此输入图像描述

Also Right Click on the Project and Select Set as Start Up Project as below 右键单击项目并选择设置为启动项目,如下所示 在此输入图像描述

Then lastly Right Click on the home page, eg or the page you wish to start up first eg index.html, and Set As Start Page as below 然后右键单击主页,例如您要首先启动的页面,例如index.html,以及设置为起始页面,如下所示

在此输入图像描述

If you have both console app and web app in the same solution, please try this, right on solution. 如果您在同一解决方案中同时拥有控制台应用程序和Web应用程序,请在解决方案上尝试此操作。 Select properties and set the Start up Projects to Multiple startup projects as below 选择属性并将启动项目设置为多个启动项目,如下所示

在此输入图像描述

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

相关问题 Visual Studio 找不到 IIS Express - Visual Studio can't find IIS Express 使用IIS Express / Visual Studio进行SimpleInjector验证过程 - SimpleInjector Verification process with IIS Express / Visual Studio 在 Visual Studio 中运行 IIS-Express 时出错 - Error running IIS-Express in Visual Studio Visual Studio 2013-IIS Express不提供aspx文件 - Visual Studio 2013 - IIS Express not serving aspx files 从 Visual Studio 2019 运行时在 IIS Express 上获取 NullReferenceException - Getting NullReferenceException on IIS Express while running from Visual Studio 2019 无法在Visual Studio 2017 RC中启动IIS Express - Unable to launch IIS Express in Visual Studio 2017 RC 文件上传在 Visual Studio IIS Express 中工作但不在服务器上 - File upload working in Visual Studio IIS Express but not on server Visual Studio 2019“无法连接到 web 服务器‘IIS Express’” - Visual studio 2019 “Unable to connect to web server 'IIS Express'” 如何在 Visual Studio 2019 中带回 IIS Express 进行调试? - How to bring back IIS Express for Debugging in Visual Studio 2019? 从 iPad 连接到 Visual Studio (IIS Express) 时出现登录问题 - Login issue when connecting to Visual Studio (IIS Express) from iPad
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM