Visual Studio 2010: How to publish an ASP.NET web application to a destination folder using MSBUILD?

In Visual Studio 2010, you know how to change the configuration (debug, release, etc.), right-click the project in the solution explorer, click the publication and have all the important web application project files for the selected configuration copied to the target folder along with xdt-converted web.config? Well, I'm looking for the equivalent of MSBUILD for just that.

My challenge to you: specify the ONE LINE that I need to execute on the command line in order to accomplish this. There are no third-party programs. No training videos. Just a single, correct command, which I can literally copy from your answer, paste into the command window, change as necessary to support my directory structure and then press enter.

If not, maybe someone can provide a link to the full MSBUILD link showing each command, switch, and value that I can use on the command line.

+6
source share
2 answers

Place the file below ProjectPublish.MSBuild.xml (change the PropertyGroup as necessary):

 <?xml version="1.0" encoding="utf-8" ?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Publish"> <PropertyGroup> <ProjectFile>Path\To\Web.csproj</ProjectFile> <PublishDir>Path\For\Publish\Output</PublishDir> <TempDir>Path\To\Temp\Folder</TempDir> <BuildConfig>Release|Debug</BuildConfig> </PropertyGroup> <Target Name="Publish"> <MSBuild Projects="$(ProjectFile)" Properties="Configuration=$(BuildConfig);WebProjectOutputDir=$(PublishDir);OutDir=$(TempDir)\;BuildingProject=true" Targets="ResolveReferences;_CopyWebApplication" /> </Target> </Project> 

Calling this from the command line (or .bat file) should do the trick:

 %windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe ProjectPublish.MSBuild.xml 
+6
source

I found the solution I was looking for after all these months here

In case the above link goes wrong, here is the skinny one from what she says:

Upload, then edit the project file. Find the line where it imports Microsoft.WebApplication.targets. It will look like this:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

Insert this XML below this line:

 <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder"> <Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." /> <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" /> <ItemGroup> <PublishFiles Include="$(_PackageTempDir)\**\*.*" /> </ItemGroup> <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" /> </Target> 

Now run this on the command line in the same folder as the project file:

msbuild TestWebApp.csproj "/p:Platform=AnyCPU;Configuration=Debug;PublishDestination=C:\pub" /t:PublishToFileSystem

Do not forget to specify the path to MSBUILD in the command or add the path to your global environment variable (this is what I did). On my car, he was here:

C:\Windows\Microsoft.NET\Framework\v4.0.30319

To check this, I put the config configuration in my Web.Release.config to add the AppSetting key (if you do, make sure the AppSettings node is present in your base configuration file or you get an error message). When I used the above command to create a debug configuration, the key was not present in the published configuration file as expected. However, when I used the release configuration, the key was successfully added to the file.

I really want Microsoft not to baffle this. In any case, this is the simplest solution I have found anywhere on the Internet. Hope this helps the rest of you.

0
source

Source: https://habr.com/ru/post/886030/


All Articles