Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some msbuild magic to deploy dependent ASP.NET Core app #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions IISCrossover.Deploy.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<Project>
<PropertyGroup>
<DisableFastUpToDateCheck Condition="'$(BuildingInsideVisualStudio)' == 'true' ">true</DisableFastUpToDateCheck>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="@(DeployProjectReference)">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>_DeployedProjectOutput</OutputItemType>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
<DeployName>$([System.IO.Path]::GetFileNameWithoutExtension(%(Identity)))</DeployName>
<Private>false</Private>
</ProjectReference>
</ItemGroup>

<Target Name="VerifyOnlyOneDeployedProject" BeforeTargets="AssignDeployedProjectTargetPaths">
<PropertyGroup>
<_IsInvalidValidDeployProjects>false</_IsInvalidValidDeployProjects>
<_HasDeployProject>true</_HasDeployProject>
<_HasDeployProject Condition=" '@(DeployProjectReference->Count())' == '0' " >false</_HasDeployProject>
<_HasOneDeployProject>false</_HasOneDeployProject>
<_HasOneDeployProject Condition=" '@(DeployProjectReference->Count())' == '1' " >true</_HasOneDeployProject>
<_IsInvalidValidDeployProjects Condition="!$(_HasDeployProject) AND !$(_HasOneDeployProject)">true</_IsInvalidValidDeployProjects>
</PropertyGroup>

<Error Condition="$(_IsInvalidValidDeployProjects)" Text="Only a single DeployProjectReference node is allowed per project" />
</Target>

<Target Name="AssignDeployedProjectTargetPaths" BeforeTargets="AddDeployedProjectsToWebConfig">
<ItemGroup>
<_DeployedProjectOutput Update="@(_DeployedProjectOutput)">
<TargetPath>projects\%(_DeployedProjectOutput.DeployName)\$([System.IO.Path]::GetFileName('%(Identity)'))</TargetPath>
</_DeployedProjectOutput>
</ItemGroup>

<MSBuild
Projects="@(_MSBuildDeployProjectReferenceExistent)"
Targets="PublishItemsOutputGroup"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildDeployProjectReferenceExistent.SetConfiguration); %(_MSBuildDeployProjectReferenceExistent.SetPlatform); %(_MSBuildDeployProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildDeployProjectReferenceExistent.DeployName)' != '' "
ContinueOnError="$(ContinueOnError)"
SkipNonexistentTargets="true"
RemoveProperties="%(_MSBuildDeployProjectReferenceExistent.GlobalPropertiesToRemove)$(_GlobalPropertiesToRemoveFromProjectReferences)">

<Output TaskParameter="TargetOutputs" ItemName="_DeployedProjectsContents"/>
</MSBuild>

<ItemGroup>
<_AllDeployedProjectFilesContent Include="@(_DeployedProjectsContents)">
<TargetPath>projects\%(_DeployedProjectsContents.DeployName)\%(_DeployedProjectsContents.TargetPath)</TargetPath>
</_AllDeployedProjectFilesContent>
<_AllDeployedProjectFilesContent Include="@(_DeployedProjectOutput)" />
<Content Include="@(_AllDeployedProjectFilesContent)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>

<Target Name="PrepareDeployProjectPaths" BeforeTargets="AddDeployedProjectsToWebConfig">
<PropertyGroup>
<__DeployedProjectTransformPath>$(IntermediateOutputPath)deployed_transform.xml</__DeployedProjectTransformPath>
<__WebConfigPath>web.config</__WebConfigPath>
<__IsPublishing>false</__IsPublishing>
<__IsPublishing Condition=" '$(PublishProfile)' != '' ">true</__IsPublishing>
</PropertyGroup>

<ItemGroup>
<_DeployProjectPaths Include="$(OutDir)%(_DeployedProjectOutput.TargetPath)">
<HostingModel>%(_DeployedProjectOutput.HostingModel)</HostingModel>
<ContentRoot>$([System.IO.Path]::GetDirectoryName(%(_DeployedProjectOutput.OriginalItemSpec)))</ContentRoot>
<TargetDirectory>$([System.IO.Path]::GetDirectoryName(%(_DeployedProjectOutput.TargetPath)))</TargetDirectory>
</_DeployProjectPaths>
<_DeployProjectPaths Condition="$(__IsPublishing)" Update="@(_DeployProjectPaths)">
<ContentRoot>%(TargetDirectory)</ContentRoot>
</_DeployProjectPaths>
<_DeployProjectPaths Update="@(_DeployedProjectOutput)" Condition=" '%(HostingModel)' == '' ">
<HostingModel>inprocess</HostingModel>
</_DeployProjectPaths>
</ItemGroup>

<Error Text="Unknown hosting model: %(_DeployProjectPaths.HostingModel)" Condition=" '%(_DeployProjectPaths.HostingModel)' != 'outofprocess' AND '%(_DeployProjectPaths.HostingModel)' != 'inprocess' " />
</Target>

<Target Name="AddDeployedProjectsToWebConfig" BeforeTargets="AssignTargetPaths">
<ItemGroup>
<__DeployedProjectTransformLines Include='&lt;configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"&gt;' />
<__DeployedProjectTransformLines Include="&lt;system.webServer&gt;" />
<!-- In order to remove, we must have a node. So, we'll add one if it's not there and then remove it. If there were 'RemoveIfExists' we could just use that -->
<__DeployedProjectTransformLines Include='&lt;aspNetCore xdt:Transform="InsertIfMissing" /&gt;' />
<__DeployedProjectTransformLines Include='&lt;aspNetCore xdt:Transform="Remove" /&gt;' />
<__DeployedProjectTransformLines Include='&lt;aspNetCore processPath="dotnet" arguments="%(_DeployProjectPaths.Identity) --contentRoot %(_DeployProjectPaths.ContentRoot)" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="%(_DeployProjectPaths.HostingModel)" xdt:Transform="Insert" /&gt;' />
<__DeployedProjectTransformLines Include="&lt;/system.webServer&gt;" />
<__DeployedProjectTransformLines Include="&lt;/configuration&gt;" />
</ItemGroup>

<WriteLinesToFile File="$(__DeployedProjectTransformPath)" Lines="@(__DeployedProjectTransformLines)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<TransformXml Source="$(__WebConfigPath)" Transform="$(__DeployedProjectTransformPath)" Destination="$(__WebConfigPath)" />
</Target>

</Project>
5 changes: 5 additions & 0 deletions LegacyApi/LegacyApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<DeployProjectReference Include="../Greenfield/Greenfield.csproj" HostingModel="inprocess" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
Expand Down Expand Up @@ -177,6 +180,8 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>

<Import Project="../IISCrossover.Deploy.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
58 changes: 31 additions & 27 deletions LegacyApi/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,59 @@
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggered! 😄

<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<compilation debug="true" targetFramework="4.7.2"/>
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="CSS" path="*.css" verb="*" type="System.Web.Handlers.TransferRequestHandler" modules="AspNetCoreModuleV2" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="Pages" path="*.aspx" verb="*" type="System.Web.Handlers.TransferRequestHandler" modules="AspNetCoreModuleV2" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" modules="AspNetCoreModuleV2" preCondition="integratedMode,runtimeVersionv4.0" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<add name="CSS" path="*.css" verb="*" type="System.Web.Handlers.TransferRequestHandler" modules="AspNetCoreModuleV2"
preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="Pages" path="*.aspx" verb="*" type="System.Web.Handlers.TransferRequestHandler" modules="AspNetCoreModuleV2"
preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" modules="AspNetCoreModuleV2"
preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
<aspNetCore processPath="dotnet" arguments="..\Greenfield\bin\Debug\netcoreapp3.1\Greenfield.dll --contentRoot ..\Greenfield" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<aspNetCore processPath="dotnet" arguments="bin\projects\Greenfield\Greenfield.dll --contentRoot ..\Greenfield" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" hostingModel="inprocess"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f"/>
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down