How can I build an ASP.NET web application from the command line?
Try this in a .bat file, replace v4.0.30319 with the appropriate version:
CD C:\Windows\Microsoft.NET\Framework\v4.0.30319
msbuild "C:\inetpub\wwwroot\MyWebSite.sln"
Take a look at the devenv.exe /Build switch, you give it a solution file to build, e.g.
devenv.exe "C:\Documents and Settings\someuser\MySolution.sln" /build DEBUG
If you have more complex build requirements then look into MSBuild.
This is a round about way to do it, but you can use the MSBuild task as part of an msbuild project:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Solutions Include="*.sln" />
</ItemGroup>
<Target Name="Build" >
<MSBuild BuildInParallel="true" Projects="#(Solutions)" RebaseOutputs="true" />
</Target>
built with msbuildprojectname.proj from the command line.
This may seem like overkill, but you can then add extra stuff into the project (like restarting websites, zipping files, Virtual machine control even!, code coverage) that can help you setup and test the project.
As dumb as I might look, I have used "aspnet_compiler.exe" for compiling/deploying projects
http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/2ca80dfd-b7d7-4e09-98ff-891b1570f4db
To build a solution directly,
msbuild mysolution.sln
You'll find MSBuild in the Microsoft.NET folder in your Windows directory.
You may also want to pre-compile your Web site. Instructions for that are on MSDN here. If you use the Web Deployment project node (detailed at the bottom) then the deployment will happen automatically when you run msbuild on the solution file.
Related
I have a web asp.net solution that is using .net core 2.0. I am building it using the command:
dotnet publish MySolution.sln --configuration release --output d:\test_output
But when I check the output folder, I'm seeing a lot of localization folders, as you can see in the image bellow:
Is there a way to publish the code without generating these folders?
For the projects using ASP.NET Core 3.1, add this line to your *.csproj file:
<PropertyGroup>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
The source of the answer in this post: Disable Dll Culture Folders on Compile.
The solution provided by #Igor.K worked for my API project, but for the ASP.NET Core MVC website in my solution, I had to make a minor change.
Try adding the line below to your .csproj file.
<PropertyGroup>
<ResourceLanguages>en</ResourceLanguages>
</PropertyGroup>
You can edit this file by right-clicking your project and selecting "Unload Project". Then, when you right-click again you will be able to edit the .csproj file. Make sure you reload the project when you're finished though.
So, if SatelliteResourceLanguages doesn't solve your problem, ResourceLanguages might do the trick.
[in net 5.0] All above solutions didn't work for me.
Out of despair I added:
<PropertyGroup>
<SatelliteResourceLanguages>en-US;en</SatelliteResourceLanguages>
</PropertyGroup>
and it worked, absolutely no idea why
On the .csproj file, you look for "Microsoft.VisualStudio.Web.CodeGeneration.Design" Package reference and add the property ExcludeAssets="All"
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" ExcludeAssets="All" />
Here is the reference: Disable Dll Culture Folders on Compile
Neither the SateliteResourceLangauges nor the ResourceLangauges solutions worked for me. In my case the files were being generated by the following nuget:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" ExcludeAssets="All" />
Affixing ExcludeAssets="All" to it as shown above resolved the issue.
I have a solution with A LOT of web projects (80+). I'm using WDP to deploy my projects to the environments, so I have a script that builds a web deploy package for each project and then each package is published.
Each package is deployed without deleting what is already there and each package can override duplicate files. It works but the deployment is quite slow.
I have a strong suspicion that having one package with all the file would be a lot faster, since from the looks of it a lot of the time is spent on the setup of the connection to the server and not much on the deployment itself (probably because many files are not updated)
Is there a way to build a single WDP from multiple web projects in visual studio solution or using MSBuild and a couple of scripts?
Thanks
Is there a way to build a single WDP from multiple web projects in visual studio solution or using MSBuild and a couple of scripts?
Since you have a script that builds a web deploy package for each project, you can try to deploy those project to the local folder, you can think of this an “intermediate publish folder”. From there you can construct a zip task to all packages to one zip file, then publish/copy this zip file to publish directly.
To accomplish this, you can create a .csproj file with following code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="Zip" AfterTargets="Build">
<CreateItem Include="YourLocalPublishFolder\*.*" >
<Output ItemName="ZipFiles" TaskParameter="Include"/>
</CreateItem>
<Zip ZipFileName="YourZipFile.zip" WorkingDirectory="YourPublishFolder" Files="#(ZipFiles)" />
With this .csproj file, all .zip are compressed into a package to the publish folder, do not need to publish each project to the publish folder.
Note: Need import the MSBuildTasks.targets to the .csproj file, which including Zip target.
Hope this helps.
I have created a publishing profile for my web page, and I can successfully publish using the web deploy interface in Visual Studio (right click project, deploy etc). It builds the project on my local PC, and copies the files across to destination IIS server.
But now I am trying to create a MSBuild command, which should do the same, but it is only building the solution, not copying it across to the server.
My MSbuild command looks like this, and I run it from the solution source directory
msbuild "test.co.za.sln" p:DeployOnBuild=true /p:PublishProfile="test.co.za" /p:UserName="domain\test" /p:Password="test"
Is there anything wrong with my build command? As you can see in the screenshot, it is building successfully, but no files are being copied across. Which makes me wonder if the publishing profile is executed at all.
I have tried various combinations of publishprofile paths, full paths, with extensions, without, nothing seems to copy my files accross.
My publishing profile looks like this App_Data\Publishprofile\test.co.za.pubxml
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<SiteUrlToLaunchAfterPublish>http://test.co.za</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<MSDeployServiceURL>test.co.za</MSDeployServiceURL>
<DeployIisAppPath>test.co.za</DeployIisAppPath>
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<UserName>domain\test</UserName>
<_SavePWD>True</_SavePWD>
</PropertyGroup>
</Project>
EDIT: This is an existing classic ASP website which I added to a solution, it doesn't contain a ".csproj" file, just a "website.publishproj", which doesn't seem to execute
It doesn't look like you are passing in the VisualStudioVersion property. You should include that. The value will either be 11.0, 12.0, or 14.0 based on the version of Visual Studio you are using. You should likely pass in a value for Configuration as well but it's not required. I've blogged about why this is important at http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx.
You can find the docs for asp.net command line publishing at http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/command-line-deployment
Looks like my "website.publishingproj" is never being built when I run the msbuild command. Not sure why, #Sayed do you perhaps know?
I had to create a targets file next to my solution called "after.solutionName.sln.targets" and copy the code from this answer : https://stackoverflow.com/a/15138373/1184603
<!--?xml version="1.0" encoding="utf-8"?-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Deploy Website" AfterTargets="Build">
<Message Text="Starting Website deployment" Importance="high">
</Message>
<MSBuild Projects="$(MSBuildProjectDirectory)\MyWebs\website.publishproj"
BuildInParallel="true" />
</Target>
</Project>
It now publishes correctly from my msbuild script.
Apparently, DNN installations do not like to be precompiled (they won't be able to find any localized strings then). Our installation is safely put in SVN, which means I cannot just copy the whole directory. To publish everything, I need to copy the whole website directory without the SVN files and directories. So far, I've been messing with good old DOS commands, which is time consuming and error prone.
Can someone help me to an MS-Built script or step to do just this? Or can I do this using default Visual Studio 2010 commands?
Note: this is a website, not a web application.
Just svn export the directory from source control, which will give you a clean copy without the .svn stuff in it.
Visual Studio -> Solution Explorer -> <web site> -> <right click> -> Publish Web Site or Copy Web Site
If you are ever interested in automating this with MSBuild then you can do that with something like the following.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<FilesToCopy Include="**\*"
Exclude="**\.svn\**"/>
</ItemGroup>
<PropertyGroup>
<Dest>C:\temp\dest\</Dest>
</PropertyGroup>
<Target Name="CopyFiles">
<Message Text="FilesToCopy: #(FilesToCopy)"/>
<MakeDir Directories="$(Dest)"/>
<Copy SourceFiles="#(FilesToCopy)"
DestinationFiles="#(FilesToCopy->'$(Dest)%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>
So when I create the FilesToCopy item I exclude all the files under any .svn folder. Then I just perform the copy inside the CopyFiles target.
I am using nant-0.90-alpha1 to build asp.net 3.5 web site. I am unable do that. When I am using msbuild , it throwing error saying unknown tag msbuild. How can I build asp.net 3.5 website using nant?
nRk
The CodeCampServer project provides good examples for a variety of tasks using nant to build MS projects including using MSBuild. However it doesn't use the msbuild task. Here's an excerpt from the common.build file from CodeCampServer:
<target name="compile" depends="init">
<echo message="Build Directory is ${dir.build}" />
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline="${file.solution} /t:Clean /p:Configuration=${project.config} /v:q" workingdir="." />
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline="${file.solution} /t:Rebuild /p:Configuration=${project.config} /v:q" workingdir="." />
</target>
<msbuild> task is part of NAntContrib.
The <msbuild> task must be imported into your build script. Put the following element somewhere within your <project> element.
<project ...>
<loadtasks assembly="C:\Program Files\NAntContrib\NAnt.Contrib.Tasks.dll"/>
...
</project>
I believe NAnt will also pick up additional task libraries if the dlls are placed in the NAnt bin folder.