Different msbuild behavior? - msbuild

While creating deployment project for my solution strange behavior have been noticed.
I'm using webdeploy for deployment of my web apps.
And when putting this
<Exec Command="$(MsBuildBinPath)\msbuild.exe $(SourceControlPath)\...\myproject.csproj /p:configuration=Release /p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MSDeployServiceUrl=https://x.x.x.x:8172/msdeploy.axd /p:MSDeployPublishMethod=WMSvc /p:DeployIisAppPath="Default Web Site" /p:username=username /p:password=password /p:AllowUntrustedCertificate=True /P:CreatePackageOnPublish=True">
</Exec>
in my deploy project file, it builds and deploys my application without issues.
But using MSBuild task with exact same set of properties
<MSBuild Properties="Configuration=$(Configuration);DeployOnBuild=True;
DeployTarget=MSDeployPublish;MSDeployServiceUrl=https://x.x.x.x:8172/msdeploy.axd;
MSDeployPublishMethod=WMSvc;DeployIisAppPath="Default Web Site";
UserName=username;Password=password;
AllowUntrustedCertificate=True;CreatePackageOnPublish=True"
Projects="$(SourceControlPath)\...\myproject.csproj"
></MSBuild>
gives me an error: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.5\Web\Microsoft.Web.Publishing.targets(4196, 5): error ERROR_COULD_NOT_CONNECT_TO_REMOTESVC: Web deployment task failed. (Could not connect to the remote computer ("x.x.x.x") using the specified process ("Web Management Service") because the server did not respond. Make sure that the process ("Web Management Service") is started on the remote computer...
So, I was thinking that basically both approaches do the same. what's wrong with 2-nd approach?

The problem may be the escaped quote you have the Properties attribute. Have you tried not including the " around Default Web Site?
One way I have used to make the file more readable is pass the arguments via an item group.
<ItemGroup>
<DeployArgs Include="Configuration=$(Configuration)" />
<DeployArgs Include="DeployOnBuild=True" />
<DeployArgs Include="DeployTarget=MSDeployPublish" />
<DeployArgs Include="MSDeployServiceUrl=https://x.x.x.x:8172/msdeploy.axd" />
<DeployArgs Include="MSDeployPublishMethod=WMSvc" />
<DeployArgs Include="DeployIisAppPath=Default Web Site" />
<DeployArgs Include="UserName=username" />
<DeployArgs Include="Password=password" />
<DeployArgs Include="AllowUntrustedCertificate=True" />
<DeployArgs Include="CreatePackageOnPublish=True" />
</ItemGroup>
<MSBuild Properties="#(DeployArgs)"
Projects="$(SourceControlPath)\...\myproject.csproj"
/>

Related

Log using NLog with Azure Devops

I am using asp.net core with NLog, here is the NLog target config
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/logs/logfile-${shortdate}.txt"
keepFileOpen="true"
encoding="utf-8" />
<target xsi:type="Null" name="blackhole" />
When I run from Visual Studio (F5), asp.net create logs folder and generate file like above configuration.
But when I deploy to Azure Webapp by Azure DevOps, it couldn't generate log file.
Is there anyway to fix this issue?
What happens if you change the NLog.config to be included in publish. Update csproj-file:
<None Update="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
The special one is CopyToPublishDirectory

Publishing ClickOnce application using NAnt and MSBuild

I'm attempting to publish a ClickOnce application using an MSBuild task within a NAnt script. The certificate is installed on the machine and I believe it's finding it, as it's now getting past an earlier problem of it not being able to get the certificate itself. However, it's now failing with the error:
[msbuild]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4512,5):
error MSB4044: The "SignFile" task was not given a value for the
required parameter "CertificateThumbprint"
The task currently is called like this:
<msbuild project="${SourceURL}/pathToProject/project.csproj" verbosity="Minimal">
<property name="Configuration" value="Client" />
<property name="Platform" value="AnyCPU" />
<arg value="/p:ApplicationVersion=${actualVersion}" />
<arg value="/p:CertificateThumbprint=XXX" />
<arg value="/p:ManifestCertificateThumbprint=XXX" />
<arg value="/t:publish" />
</msbuild>
How should I be passing the CertificateThumbprint into the publish task? I'm trying to avoid having to switch directly to using signtool or mage, since I'd like to keep it as close as possible to using Visual Studio directly as possible.

Msbuild just produces a package but does not deploy it when using a publish profile. Why?

MSBuild really seems to like me.
Recently I am trying out the different possibilities to build and deploy from command line.
However I am experiencing some seemingly strange behaviour when I pass a publish profile to MSBuild.
Here is an example of what I just did:
I deploy to a local IIS for the moment with a command such as this:
msbuild D:\PathToFile\DeployDBVariation01\DeployDBVariation01\DeployDBVariation01.csproj
/p:Configuration=Release;
Platform=AnyCpu;
DeployOnBuild=true;
DeployTarget=MSDeployPublish;
MSDeployServiceURL="localhost";
DeployIisAppPath="DeployApp/DeployThis";
MSDeployPublishMethod=InProc;
Username=thisIsNotActuallyMyUsername;
password=guesswhat;
AllowUntrustedCertificate=true
And this works! After that it is successfully deployed and I can call it in a browser.
However, since Visual Studio gives us the comfort of using publishing profiles I wanted to try that in conjunction with MSBuild over command line and tried the following command:
msbuild D:\PathToFile\DeployDBVariation01\DeployDBVariation01\DeployDBVariation01.csproj
/p:DeployOnBuild=true;
AllowUntrustedCertificate=true;
PublishProfile=ReleaseLocal
ReleaseLocal is a profile I created in Visual Studio and it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>DeployApp/DeployThis</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="DefaultConnection" Order="1" Enabled="False">
<Destination Path="Data Source=.\SQLEXPRESS;Initial Catalog=HorstDataProductive;User ID=sa;Password=GuessWhat" />
<Object Type="DbDacFx">
<PreSource Path="Data Source=.\SQLEXPRESS;Initial Catalog=HorstData;User ID=sa;Password=GuessWhat" includeData="False" />
<Source Path="$(IntermediateOutputPath)AutoScripts\DefaultConnection_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
</Object>
<UpdateFrom Type="Web.Config">
<Source MatchValue="Data Source=.\SQLEXPRESS;Initial Catalog=HorstData;User ID=sa;Password=GuessWhat" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
</UpdateFrom>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String">
<ParameterValue>Data Source=.\SQLEXPRESS;Initial Catalog=HorstDataProductive;User ID=sa;Password=GuessWhat</ParameterValue>
</MSDeployParameterValue>
</ItemGroup>
</Project>
As you can see I have some additional connection string replacement there that I want to test.
So I execute that last MSBuild-command that I have shown you and it executes without any errors. Instead it says that the web deployment task was successful and that a package has been created in a certain path. Now that is actually the right package. When I import that manually in my IIS it is the result I expect, also the connection string replacement has been done.
But I do not understand why it actually is just creating the package but not deploying it in one run, like in my first command.
Can someone explain?
(Or even better, what do I have to do to make it also deploy that package immediately)
You need to specify the VS version.
http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/command-line-deployment
msbuild /P:DeployOnBuild=True /P:VisualStudioVersion=11.0 /P:PublishProfile=Dev.pubxml
Don't forget to allow untrusted certs if you're using a 'fake' internal certificate
Looks like you're missing the deploy target.. it's got all the necessary info, but doesn't know what you want it to do. Try this;
msbuild D:\PathToFile\DeployDBVariation01\DeployDBVariation01\DeployDBVariation01.csproj
/p:DeployOnBuild=true;DeployTarget=MSDeployPublish;AllowUntrustedCertificate=true;PublishProfile=ReleaseLocal

How do I specify where MSBUILD publishes a web service too?

I've seen lots of info on the web about this, but nothing clear & specific which seems to address the problem of simply publishing a web service or web site to a specific folder that I specify at build time.
I'm using Nant and Nant Contrib:
<target name="build" description="builds the service">
<msbuild project="${buildoutput}\${service.source}\wsMyService.sln" >
<property name="Configuration" value="Release" />
<property name="PublishDir" value="${buildoutput}\${service.target}\" />
<property name="Targets" value="Publish" />
</msbuild>
</target>
Can anyone show me how this is supposed to be done. I can change the output folder in the property pages of the project, but I want this to be configurable from Nant so I can specify the path at build time.
When you call msbuild from the command line, you can pass in strings to assign to msbuild properties. I don't know anything about NAnt, so I assume it has to resort to a calling msbuild.exe. So you can override msbuild properties like this:
MsBuild /property:buildoutput=C:\arbitrary\folder\bin\
These properties specified from the command line override anything you specify in your build files.
This is what im currently using to build webservices using msbuild:
<Target Name="BuildWebService">
<ConvertToAbsolutePath Paths="$(Root)">
<Output TaskParameter="AbsolutePaths" PropertyName="Root" />
</ConvertToAbsolutePath>
<ItemGroup>
<WebServices Include="$(Root)\services\Solutions\**\*.host.csproj"/>
</ItemGroup>
<MSBuild Projects="%(WebServices.FullPath)"
Targets="Build"
Properties="WebProjectOutputDir=$(Root)\services\build\WebService\%(RecursiveDir);OutDir=$(Root)\services\build\WebService\%(RecursiveDir)\bin\" />
</Target>
Hope you can translate to nant easy enough.

How do you use MSDeploy to sync a whole solution over http?

I'm able to use MSDeploy to deploy one project at a time with the Visual Studio 2010 SP1 "Publish" wizard. I deploy over http.
My visual studio solution contains many projects and some depends on shared DLL. Is it possible to sync a whole solution?
My goal would be to fully automate deployment.
Carl
Why don't you use WDeploy directly from the command line? You can specify a manifest file, where you'd put all necessary components for deployment and then sync against manifest msdeploy provider:
Source manifest (Source.xml)
<MyDeployment>
<appHostConfig path="MyLocalSiteName" />
<!--
You can also use iisApp depending on what permissions you have on the remote server.
If you have permissions execute appHostConfig that will create a site if the site does not exist.
-->
<iisApp path="MyLocalSiteName\MyApp" />
<dirPath path="C:\Solution\Project1" />
<dirPath path="C:\Solution\Project2" />
<gacAssembly path="My.GACed.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111'" />
</MyDeployment>
Destination manifest (Destination.xml)
<MyDeployment>
<appHostConfig path="MyRemoteSiteName" />
<iisApp path="MyRemoteSiteName\MyApp" />
<dirPath path="\\RemoteServerShare\Solution\Project1" />
<dirPath path="\\RemoteServerShare\Solution\Project2" />
<gacAssembly path="My.GACed.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111'" />
</MyDeployment>
And the command line would be:
msdeploy.exe -verb:sync -source:manifest=Source.xml -dest:manifest=Destination.xml,computername=MyServer
... to go against MSDeploy agent, or
msdeploy.exe -verb:sync -source:manifest=Source.xml -dest:manifest=Destination.xml,wmsvc=MyServer,username=User2,password=4321,authtype=basic
... to against WMSvc.
This blog post can get you started on the manifest provider and this TechNet article can explain some useful provider settings.