Azure Web Job: msbuild: How to publish without Debug DLLs?

697 views Asked by At

I have a Visual Studio solution comprising an Azure web app and some Azure web jobs. I have a command line script to publish an Azure web job. My problem is that the publish script builds the software and pulls in Debug DLLs instead of Release DLLs.

> msbuild.exe    "c:\git\2\Code\Server\Jobs\Azure\My.Web.Jobs.Number1Script.WebJob\My.Web.Jobs.Number1Script.WebJob.csproj" /p:DeployOnBuild=true /p:PublishProfile="qa-My-sanity - Web Deploy" /p:VisualStudioVersion=14.0 /p:Password="password" /verbosity:minimal /filelogger  /flp:logfile=number1_development.log

I think that the solution file My.sln contains information about various compile configurations, but they are not in the .csproj file.

How can I configure my publish such that Debug DLLs are not pulled into the published software?

The My.Web.Jobs.Number1Script.WebJob.csproj file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{1EEB8236-718C-4860-BE73-0E95CB3ABC82}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>My.Web.Jobs.Number1Script.WebJob</RootNamespace>
    <AssemblyName>My.Web.Jobs.Number1Script.WebJob</AssemblyName>
    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\</SolutionDir>
    <RestorePackages>true</RestorePackages>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <TargetFrameworkProfile />
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <SignAssembly>true</SignAssembly>
  </PropertyGroup>
  <PropertyGroup>
    <AssemblyOriginatorKeyFile>..\..\..\..\..\Certificates\My Corporation.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>bin\x64\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.Azure.WebJobs, Version=1.0.1.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Microsoft.Azure.WebJobs.Core.1.0.1\lib\net45\Microsoft.Azure.WebJobs.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.Azure.WebJobs.Host, Version=1.0.1.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Microsoft.Azure.WebJobs.1.0.1\lib\net45\Microsoft.Azure.WebJobs.Host.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.Data.Edm, Version=5.6.4.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Functions.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="packages.config" />
    <None Include="Properties\PublishProfiles\qa-My - Web Deploy.pubxml" />
    <None Include="Properties\PublishProfiles\qa-My-sanity - Web Deploy.pubxml" />
    <None Include="Properties\webjob-publish-settings.json" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\My.Web.Jobs.Number1Script\My.Web.Jobs.Number1Script.csproj">
      <Project>{2c99c938-4a66-4bb9-a237-3192428f5618}</Project>
      <Name>My.Web.Jobs.Number1Script</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\My.Web.Jobs\My.Web.Jobs.csproj">
      <Project>{b1c602b2-7cb4-489b-9dec-a920f963c8e1}</Project>
      <Name>My.Web.Jobs</Name>
    </ProjectReference>
    <ProjectReference Include="..\My.Web.Jobs.WebJob\My.Web.Jobs.WebJob.csproj">
      <Project>{a2c68e89-a4eb-4a07-b8da-384010914104}</Project>
      <Name>My.Web.Jobs.WebJob</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.5">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>
  <Import Project="..\..\..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.9\tools\webjobs.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.9\tools\webjobs.targets')" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

When I publish the job through Visual Studio, I have a build configuration called "Release - Azure". I can do a pure build (no publish) using this line:

> msbuild.exe "c:\git\2\Code\My.sln" /fileLogger /verbosity:minimal /p:Configuration='Release - Azure'

When I do that, the code is built, and Debug DLLs are not pulled in. But if I publish using the .csproj file, the Debug DLLs get pulled in.

I also tried the publish command using the same command, but suffixed with:

/p:Configuration=Release

That gave errors. I tried:

/p:Configuration="Release - Azure"

That gave errors too.

In my My.sln file, I have lines relating to "Release - Azure". They look like this:

Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Local|Any CPU = Local|Any CPU
        Local|x64 = Local|x64
        Local|x86 = Local|x86
        Release - Azure|Any CPU = Release - Azure|Any CPU
        Release - Azure|x64 = Release - Azure|x64
        Release - Azure|x86 = Release - Azure|x86
        Release - Windows|Any CPU = Release - Windows|Any CPU
        Release - Windows|x64 = Release - Windows|x64
        Release - Windows|x86 = Release - Windows|x86
        Release|Any CPU = Release|Any CPU
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection

There are lots of sections which look like:

    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxxx}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|x64.ActiveCfg = Debug|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|x64.Build.0 = Debug|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|x64.Deploy.0 = Debug|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|x86.ActiveCfg = Debug|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|x86.Build.0 = Debug|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Debug|x86.Deploy.0 = Debug|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|Any CPU.ActiveCfg = Release|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|Any CPU.Build.0 = Release|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|Any CPU.Deploy.0 = Release|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|x64.ActiveCfg = Debug|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|x64.Build.0 = Debug|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|x64.Deploy.0 = Debug|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|x86.ActiveCfg = Debug|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|x86.Build.0 = Debug|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Local|x86.Deploy.0 = Debug|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|Any CPU.ActiveCfg = Release|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|Any CPU.Build.0 = Release|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|Any CPU.Deploy.0 = Release|Any CPU
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|x64.ActiveCfg = Release|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|x64.Build.0 = Release|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|x64.Deploy.0 = Release|x64
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|x86.ActiveCfg = Release|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|x86.Build.0 = Release|x86
        {6B1EABD4-433F-4E70-9EFB-xxxxxxxxxxxx}.Release - Azure|x86.Deploy.0 = Release|x86

        ...
    EndGlobalSection

My .pubxml file looks like this:

<?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>MSDeploy</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release - Azure</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://qa-My-sanity.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <MSDeployServiceURL>qa-My-sanity.scm.azurewebsites.net:443</MSDeployServiceURL>
    <DeployIisAppPath>qa-My__sanity</DeployIisAppPath>
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <UserName>$qa-My__sanity</UserName>
    <_SavePWD>True</_SavePWD>
    <_DestinationType>AzureWebSite</_DestinationType>
  </PropertyGroup>
</Project>
1

There are 1 answers

2
Amor On

/p:PublishProfile="qa-My-sanity - Web Deploy"

In the publish profiles file, there is a property named LastUsedBuildConfiguration which will specify the build version. Please change it to any build version you want.

<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>