I'm using Visual Studio 2017 (ver15.6.6) with .NET Framework ver4.7.02558 (MSBuild ver15.5.x) aka latest updates at the time of this writing. When I create an ASP.NET Web Project using the default template the resulting .csproj file contains this snippet:
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
[...]
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
As you can see Microsoft.WebApplication.targets is imported twice. I'm scratching my head over this block of the .csproj:
- First of all the 2nd entry is disabled due to Condition="false" (am I missing something here?) So this begs the question what's the deal with this import statement in the first place?
- Second of all the 2nd statement points to v10.0 instead of v15.0. Errrr woOt? Shouldn't it be v15.0?
Third of all this bit:
< VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0< / VisualStudioVersion>
should probably be:
< VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0< /VisualStudioVersion>
For testing purposes I commented out the first statement and enabled the second one like so:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" Condition="true" />
This seems to work just fine both in my dev machine and the headless CI server we have. I'm mentioning this because if the default \v10.0\ is used then the build system breaks in a very esoteric manner down the road:
In our CI server the web-publish mechanism silently fails to spawn anything in the output folder and at the same time it produces no error whatsoever (gah!).
This is a known issue which seems to be affecting many users. Checkout the answer by rianjs here:
https://github.com/Microsoft/msbuild/issues/1901
He came to the same conclusion as I did. I can't fathom why the default template for VS17 doesn't have built in provisions to address such subtleties in the default build system as illustrated above.
All these default settings of the .csproj seem way off, completely misleading and constitute batteries for all sorts of weird, silent and hard-to-figure-out errors. Especially when it comes to CI servers.
In order to resolve these issues with the default templates do I need to update the templates of visual studio separately through an addon or something to get healthy templates for VS17? What's going on here?