MSbuild Website Not Publishing to Local Directory - asp.net

I need to publish a .NET web site project to a local directory. The web site project is part of a solution that also contains a web app. The Publish Web App option in Visual Studio publishes the web site to the directory without issue, however I am unable to publish the site through msbuild.
My msbuild command
msbuild "C:\...\ProjectName\website.publishproj" /p:deployOnBuild=true /p:publishProfile=Dev /p:PrecompileBeforePublish=false /p:VisualStudioVersion=14.0 /p:WebPublishMethod=FileSystem
The dev.pubxml publish profile I am referencing is:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>C:\FolderLocation</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeFoldersFromDeployment>.vs</ExcludeFoldersFromDeployment>
</PropertyGroup>
</Project>
Currently the web site is not publishing to C:\FolderLocation but instead appears to publish to ProjectName\PrecompiledWeb\localhost_51636. Changing the output directory via /p:OutDir=C:\FolderLocation publishes the web app to the correct location, however it does not publish the web site. I have also tried both /p:PublishDestination and /p:DesktopBuildPackageLocation msbuild arguments however the original issue remains.
I have referenced Publish Artifacts for website goes to PrecompiledWeb and many other resources. My eventual goal is to setup CI through Azure Devops for the entire legacy .NET website project.

With TFS - it is using MSBUILD under the covers and we need this parameter to write to a directory for artifacts to be pulled from
/p:OutDir=$(build.StagingDirectory)
You are telling it only about the Publish Project part - see if putting your SLN file there at the first parameter solves it and does all of them.

Related

How to copy appsettings.json to DEBUG folder, as part of dotnet build

I am having a console application, which is using appsettings.json for holding the configuration values.
In Visual Studio IDE , when I set AlwaysCopy for appsettings.json, it will be copied to the DEBUG folder, as part of BUILD.
But, in .net core, when I run dotnet build, it is not copying appsettings.json to DEBUG folder.
I am already having below xml configuration added to .csproj
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
When I do dotnet publish, it is getting copied to publish folder. But, it is not happening when I do dotnet build. Can you please tell, why it is not happening & what should I do to copy the appsettings.json to DEBUG folder?
Found the answer in another thread is Stackoverflow(The difference between build and publish in VS?). In .NET Core, build & publish are different, as compared to .NET Framework.
Building .NET Framework applications will generate the same files as
Publish. It will create all the dependencies as binaries including
external dependencies(NuGets for instance). So the product of dotnet
build is ready to be transferred to another machine to run
Building .NET Core applications, if the project has third-party
dependencies, such as libraries from NuGet, they're resolved from the
NuGet cache and aren't available with the project's built output.
Therefore the product of dotnet build isn't ready to be transferred to
another machine to run. You need to run Publish to get all 3rd party
dependencies as binaries in output folder.
If we want a file to be part of publish, we need to add below attribute. In build, this file is not copied to the DEBUG/RELEASE folder.
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>

I can't create an Azure backend template VS 2019

I'm following this tutorial https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter1/firstapp_pc/ and at some point it creates an ASP.NET project and loads and Azure Mobile App template.
When I redo these steps in my VS2019 I don't have the option of Azure Mobile App (I have Azure installed). The options are, Empty, Web Forms, MVC, Web API and Single Page Application
There is a backend example that can be downloaded here https://github.com/Azure/azure-mobile-apps-quickstarts/pull/126. However, if I do that my project and solution already have a name I don't want and it's tedious to change and easy to make mistakes.
Try this
create function .csproj file manual using below content
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
save this file as myfunction.csproj.
right click solution and choose add existing project and choose project created in step 2
now u can start working on this by adding references and function code.

Deploying a command-line .net core 2.2 app using Azure DevOps piplines

I have a command-line client written C# targeting .net core 2.2 (not an asp.net core, just a command-line app).
I'm trying to distribute that application to a group of servers using Azure DevOps pipelines.
Unfortunately, I cannot get the Visual Studio build action to create a complete package.
To deploy using the locally compiled package, I create a publish "Folder" profile that works fine. I hoped to be able to tell the action to do the same and copy the result to the Artifact Staging directory but, unfortunately, it does not seems to work.
I'm using the following MSBuild arguments:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:PublishProfile="FolderProfile"
The profile is defined as such:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PublishDir>..\ClientPublish\</PublishDir>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
</PropertyGroup>
</Project>
From what I can see in the compilation log, the "DeployOnBuild" parameter is simply ignored and the application is never deployed.
What am I doing wrong ?
Edit
Here is a screenshot of my most recent attempt using a deployment profile:
Copy file:
And artifact publish:
Alternatively, I tried it like this after disabling the file copy task:
After a lot of back and forth this is the correct pipeline for it to work:
SDK Installer task first (Similar to Nuget Installer for .NET Framework)
.dotnet restore (similar to Nuget Restore for .NET Framework)
Build Solution
And then add .dotnet publish to create an artifact (This step needs to be added after the build)
Publish Artifact to drop the artifact for the release pipeline to pick up.
Seems like MSBuild arguments are not needed in this case. The built in pipelines will do everything on their own.

Visual Studio .NET publish - How to run a command before "Publish" that generates code

I am using Visual Studio 2012 and am working with a JavaScript framework (Ext JS). My HomeController basically redirects to the index that Ext JS uses. It communicates with other Visual Studio projects that actually make use of .NET (via CORS), but this particular project just contains my JavaScript application.
I want to publish this Visual Studio project, but there is a catch. A tool that is used with Ext JS, named Sencha Command, is used to create a production version of the JavaScript application. It basically creates a stand-alone build folder that contains all the JavaScript scripts combined and minified, required resources, compiled Sass, etc. It works out really well in some scenarios, but I am not sure how to make it play nice with Visual Studio on publish.
I have figured out how to get the sencha command to run with a post-build command that checks to see if I am in debug mode or not, but I don't want the generated folder to be part of my actual project, and I don't want the not-yet-compiled code to be published either. I know how to omit a folder in my pubxbml file. But I need to do something like move the build folder to the publish location.
Has anyone encountered scenarios such as this? Is there a better way to go about this?
Here is my current pubxml:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<publishUrl>C:\Users\TestUser\Desktop\Release</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeFoldersFromDeployment>
js/ext;js/App
</ExcludeFoldersFromDeployment>
</PropertyGroup>
<Target Name="BeforePublish" BeforeTargets="FileSystemPublish">
<Exec Command="echo Hello" />
</Target>
</Project>
Note: I don't think the BeforePublish worked. I tried a number of commands there, including the "sencha app build" command which I later moved to a post-build command.

Can TeamCity publish a Web project using the sln2008 build runner?

I'm building an ASP.Net MVC project in TeamCity.
Can I somehow call the Publish target and get the output copied to a folder under IIS? or do I need to write an msbuild script for this?
I've written a pretty long blog post on this very topic that may interest you:
http://www.diaryofaninja.com/blog/2010/05/09/automated-site-deployments-with-teamcity-deployment-projects-amp-svn
basically:
install web deployment projects
add web deployment project to your solution
setup the solution configuration manager to have a "Deployment" build configuration
get team city to use this build switch when running the build
have a beer and wonder in glory at your automagical awesomenesss
Have you tried a Web Deployment Project (WDP)? I have multiple Web Application Projects (WAP) with associated WDPs that work great with TeamCity for deployment scenarios.
I use the sln2008 runner to build my solution (containing both the WAP and the WDP). I've modified the WDP project file (an MSBuild script) to copy the output to a network share:
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Deploy' ">
<!-- copy WDP output to \\build02\wwwroot\Belden.Web.Intranet\ -->
<ItemGroup>
<MySourceFiles Include="$(OutputPath)**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(MySourceFiles)" DestinationFiles="#(MySourceFiles->'\\build02\wwwroot\Belden.Web.Intranet\$(ProjectDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
I haven't tried this with MVC/WDP, but I imagine it would work the same ...
I believe you can: Publish sln. Have a look at the targets. Hopefully it will lead you in the right direction.
I also had a look at this a while ago but could but had no luck with publishing targets, maybe because my IIS resided on a different server.
Here is how I did it anyway, hope it helps TeamCity deletes files on build have a look at the accepted answer.

Resources