-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support Publish to IIS from withing Visual Studio using the GUI #21
Comments
@Kation Publish already works from the command line or build server. Is this to enable the publish command in visual studio? <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" /> I feel that adding the Your example does not include the Have you tried the following? <Project>
<Import Sdk="MSBuild.SDK.SystemWeb/4.0.33" Project="Sdk.props" />
<Import Sdk="Microsoft.NET.Sdk.Publish" Project="Sdk.props" />
<ItemGroup>
<ProjectCapability Include="DotNetCoreWeb" />
<ProjectCapability Include="Web" />
</ItemGroup>
<Import Sdk="MSBuild.SDK.SystemWeb/4.0.33" Project="Sdk.targets" />
<Import Sdk="Microsoft.NET.Sdk.Publish" Project="Sdk.targets" />
</Project> This will add the |
@CZEMacLeod Yes. This allow us publish to IIS in Visual Studio. |
@CZEMacLeod and @Kation |
@christianbumann This was never added to the main SDK as it didn't feel like it worked as intended and caused side effects. The fact that it works from the command line means it is easy to integrate this with any CI/CD system, and other than for small/test projects, which wouldn't really benefit from this SDK, it seems like an unlikely use case to be publishing from VS directly. |
@CZEMacLeod Thank you for your quick answer. Publishing local from Visual Studio would get a faster feedback how the final package content looks like. Deploying from the pipeline is in plan as the build artefact (deployment package) itself already exists.... Our developers can take the build artefact and extract it if required - or build the solution locally through our Cake-scripts and then the package is also available local.... |
@christianbumann Ah I see. The only thing I can suggest here is to create a batch file in the solution directory and add it to the solution. That way you can execute the batch file from within VS and do the publish command and then investigate the output files etc. |
@christianbumann Maybe try one of the following
@CZEMacLeod I think there might be a conflict between the "order of operations" in terms of how Visual Studio runs the publish vs running a build. It was something I was investigating but never finished looking into. I was trying to document the differences between (and the interactions around) the "MvcBuildViews" and the "PreCompileBeforePublish" and how this changed order a little bit when in a ".net core build" as opposed to the original "build", and this as far as I made it when I stopped. MvcBuildViews target
PreCompileBeforePublish
I think the conflict comes into play because of when The oldest VS I currently have installed is 2017, so I can't tell for sure, but by VS 2017 it seems like web project templates
|
@leusbj Thank you for your suggestions. I tried it but without success. I also combined |
@CZEMacLeod Is there any chance you could add a 'For Dummies' sample showing how to get publish to work from the command line? So far if I call msbuild using a simple build script with a VS 2022 cmd prompt I get the website bin directory contents copied to the specified PublishDir path, but not the expected Asp.Net folder structure with a web.config, global.asax, Views, bin dir etc. that I get doing the same kind of build with the old csproj style (output created in a _PublishedWebsites folder). I also tried using 'dotnet build' but that fails due to your Sdk.targets getting the wrong MSBuildExtensionsPath32. I'm just trying this with the basic site from the template here, should it work with the dotnet CLI, I used that to install the template? |
Hm, that should work. Your deployment command should look something like: msbuild /t:Restore,Rebuild /p:DeployOnBuild=true /p:PublishProfile=Dev.pubxml `
/p:Password=$pass /p:Configuration=MyBuildConfig .\MyProject.csproj This assumes you've created a <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Beta</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>(some host name)</MSDeployServiceURL>
<DeployIisAppPath>(the web site in IIS)</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>(your username, on the server)</UserName>
</PropertyGroup>
</Project> Maybe it's something about your |
@MalcolmEllis This has been covered somewhat in issues #12 and #20 You cannot use dotnet as, not only does it not pick up the Web.Application build tasks which are only available from MSBuild included in VS - those tasks are not compatible is netcore so cannot run under dotnet. msbuild /t:Publish /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingeFile=true /p:PackageLocation="MyPublishDir" msbuild "path\to\your\solution.sln" /t:rebuild ^
/p:Configuration=Release ^
/p:DeployOnBuild=True ^
/p:DeployDefaultTarget=WebPublish ^
/p:WebPublishMethod=FileSystem ^
/p:DeleteExistingFiles=True ^
/p:publishUrl="path\to\your\output\folder" should both work. Note that you should do a nuget.exe restore before the build. I think @chucker's example of doing /t:restore,rebuild should work too, but that is not the way I do it. If you are using azure pipelines you can use something like (taken from a working commercial implementation) - task: NuGetToolInstaller@1
displayName: 'Use NuGet 6.2.1'
inputs:
versionSpec: 6.2.1
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
feedsToUse: config
nugetConfigPath: NuGet.Config
- task: VSBuild@1
displayName: 'Build solution'
inputs:
solution: '$(Parameters.solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: PublishSymbols@1
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
continueOnError: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)' I'm open to PRs adding to the documentation - especially with tested snippets. |
@CZEMacLeod why not the Sdk.props and Sdk.targets only import what the "WebProject" import ? |
@John0King What exactly do you mean by that? The SDK handles a lot of functionality that was provided by Visual Studio explicitly for Web Application Projects, such as binding redirects, handling launching IIS/IISExpress and so on. The SDK does import the same built in targets as a legacy WAP file in <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" /> This specific issue is that VS has custom handling for Publish for legacy projects, which isn't triggered in SDK projects, and trying to reuse the dotnetcore/aspnetcore publish targets doesn't exactly work, due to the differences between dotnetcore/aspnetcore and asp.net 4.x
|
@John0King If you want to continue this - we should move it to a discussion as this issue doesn't really relate to what you are talking about. The basic new project file is as simple as <Project Sdk="MSBuild.SDK.SystemWeb/4.0.88">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Include="Properties\launchSettings.json" />
</ItemGroup>
</Project> I'm pretty sure there is a lot of information on the new style SDK projects out there, including on the MS Learn website. |
Can this issue be renamed to make it explicit we are talking about publishing to IIS through Visual Studio specifically? I was browsing the issues on the repo to see if there was anything I considered major and this issue here immediately jumped to me. After finding out it works just fine via cmdline the criticality of this drops massively for me. Renaming it to be more precise would potentially save other people from similar confusion. |
Add this to enable publish to IIS feature
The text was updated successfully, but these errors were encountered: