I've been having problems with IIS Express for the past few years since we stopped using regular IIS in our projects. We typically have solutions that have a web service and some kind of client(web, desktop, or both). 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. A full rebuild always fixes this problem. HOWEVER, this is something that I have dealt with in VS2013 and VS2015 along with my coworkers. 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. 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. 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). Assuming the WcfService folder is in the same solution,
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. It's better to use the Clean task in the project, e.g. by adding this to your .csproj (under the root element, e.g. before </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.
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).
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>