Azure continuous integration testing fails with System.OperationCanceledException error - multithreading

I have this netcore 3.1 C# Web application that we setup a batch of integration tests. The tests pass when run locally, but a few keep failing when run on the CI server with the System.OperationCanceledException error.
Here is log for the CI testing environment:
==============================================================================
Task : Visual Studio Test
Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version : 2.170.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/test/vstest
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : Z:\a\1\s
Action when minimum tests threshold not met : donothing
Minimum tests expected to be run: 0
VisualStudio version selected for test execution : 16.0
Attempting to find vstest.console from a visual studio installation with version [15.0,17.0).
Run in parallel : true
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : true
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Source filter: **\*Test.dll,**\*TestIntegration.dll,!**\*TestAdapter.dll,!**\obj\**,!**\submodules\**
SystemVssConnection exists true
[command]Z:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420cc\2.170.1\Modules\DTAExecutionHost.exe --inputFile D:\a\_temp\input_eedfb280-073a-11eb-bdb8-5118fbbc2831.json
======================================================
##########################################################################
DtaExecutionHost version 18.170.30112.1.
Starting TestExecution Model...
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Result Attachments will be stored in LogStore
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Updated Run Settings:
<RunSettings>
<RunConfiguration>
<MaxCpuCount>0</MaxCpuCount>
<BatchSize>1000</BatchSize>
<ResultsDirectory>Z:\c\_temp\TestResults</ResultsDirectory>
</RunConfiguration>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="blame" enabled="True">
<Configuration>
<ResultsDirectory>Z:\c\_temp\TestResults</ResultsDirectory>
<CollectDump />
<CollectDump />
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
<LoggerRunSettings>
<Loggers>
<Logger friendlyName="blame" enabled="True" />
</Loggers>
</LoggerRunSettings>
</RunSettings>
The raw log that shows the exception is as below:
Error Message:
System.OperationCanceledException : The operation was canceled.
Stack Trace:
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.IO.Pipelines.Pipe.ReadAsync(CancellationToken token)
at System.IO.Pipelines.Pipe.DefaultPipeReader.ReadAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.TestHost.ResponseBodyReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.IO.Stream.CopyToAsyncInternal(Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
at System.Net.Http.HttpContent.LoadIntoBufferAsyncCore(Task serializeToStreamTask, MemoryStream tempBuffer)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)

Related

AppSelfHoseBase generates error when starting in .net 5

I am trying to create an apphost in the testing project of a project created from .net 5.0 react template.
I am getting the error:
OneTimeSetUp: System.TypeLoadException : Could not load type 'Microsoft.Extensions.Primitives.InplaceStringBuilder' from assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
And the breakpoint inside Configure() isn't hitting.
Same code seems to work fine in a .net 3.1 project.
Here is gist of app host:
public class MainAppHost : AppSelfHostBase
{
public MainAppHost() : base(nameof(MainAppHost), typeof(MyServices).Assembly) { }
public override void Configure(Container container)
{
//having this blank still triggers error
}
}
Seems error is thrown on AppHost.Start(url).
Stack trace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /_/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs:line 375
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs:line 18
at NUnit.Framework.Internal.Reflect.Construct(Type type, Object[] arguments) in /_/src/NUnitFramework/framework/Internal/Reflect.cs:line 113
at NUnit.Framework.Internal.TypeWrapper.Construct(Object[] args) in /_/src/NUnitFramework/framework/Internal/TypeWrapper.cs:line 252
at NUnit.Framework.Internal.Commands.ConstructFixtureCommand.<.ctor>b__0_0(TestExecutionContext context) in /_/src/NUnitFramework/framework/Internal/Commands/ConstructFixtureCommand.cs:line 51
at NUnit.Framework.Internal.Commands.BeforeTestCommand.Execute(TestExecutionContext context) in /_/src/NUnitFramework/framework/Internal/Commands/BeforeTestCommand.cs:line 48
at NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformOneTimeSetUp() in /_/src/NUnitFramework/framework/Internal/Execution/CompositeWorkItem.cs:line 262
I saw a similar issue on NUnit github caused by 3.1 and 5.0 installed on same system so I uninstalled all older versions of SDK but it made no difference.
A simple NUnit test without the apphost works fine:
public class SimpleTestClass
{
[Test]
public void SimpleTest()
{
Assert.That(1 + 1 == 2);
}
}
But if I try to create the AppHost then I get the error:
public class SimpleTestClass
{
public SimpleTestClass()
{
var AppHost = new MainAppHost()
.Init()
.Start("http://localhost:5619/");
}
[Test]
public void SimpleTest()
{
Assert.That(1 + 1 == 2);
}
}
The testing and service layer both target .net 5.0 and the project runs fine, I just can't create an AppHost for testing.
Any idea what I am doing wrong?
edit:
I found exact reproduction steps:
x new react-spa TestAppHost
update all packages
run default integration test it will work
right click testing project and select "User Secrets", install prompted package.
run same integration test it now fails with error. Nunit tests without AppHost will still work fine.
Here is project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
<UserSecretsId>1f094c52-e2b1-44e1-8e3a-9cf5189d8800</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestAppHost.ServiceInterface\TestAppHost.ServiceInterface.csproj" />
<ProjectReference Include="..\TestAppHost.ServiceModel\TestAppHost.ServiceModel.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.*" />
<PackageReference Include="ServiceStack" Version="5.*" />
<PackageReference Include="ServiceStack.Kestrel" Version="5.*" />
</ItemGroup>
</Project>
Edit after repro steps provided. The issue is with referencing v5.0.0 of UserSecrets as ServiceStack's .NET Standard 2.0 builds used in .NET 5.0 Apps only references v2.2.0 which you can change it to to resolve the issue, i.e:
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
When .NET 6 LTS is out we'll provide a new framework target for all ServiceStack libraries targeting net6.0 which will let you reference the latest dependency versions.
Unfortunately I've never seen this issue or know how to repro it.
Here's a simple way to create an NUnit Integration test project:
$ mkdir SimpleTestCase && cd SimpleTestCase
$ x mix init-test
$ dotnet test
By default this runs the integration test in both .NET 5.0 and .NET Framework v4.7.2, which should result in the test passing in both .NET platforms:
You can change it to only run in .NET 5.0 by replacing:
<TargetFrameworks>net5.0;net472</TargetFrameworks>
with
<TargetFramework>net5.0</TargetFramework>
If that fails, find which versions of .NET Core you have installed:
$ dotnet --list-sdks
3.1.120 [C:\Program Files\dotnet\sdk]
3.1.414 [C:\Program Files\dotnet\sdk]
5.0.104 [C:\Program Files\dotnet\sdk]
Then create a global.json in your project directory with the latest v5 you have installed, e.g:
{
"sdk": {
"version": "5.0.104"
}
}
This ensures that specific .NET version is used to run/test your project, which you can verify by running:
$ dotnet --version

.netcore 3.1 Publish tasks error in Azure

today i am getting error on publish tasks of .netcore app 3.1 in Azure. Publish error, after getting search on google I have added another tasks "Use .Net Core sdk 3.1" by following this link web URL and thinks it will done but running same error, the Agent i am using is "Window 2019" please find the below log, and tell me what i am doing wrong.
2020-01-10T07:23:54.1832757Z ##[section]Starting: Publish
2020-01-10T07:23:54.1955402Z ==============================================================================
2020-01-10T07:23:54.1955499Z Task : .NET Core
2020-01-10T07:23:54.1955578Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2020-01-10T07:23:54.1955801Z Version : 2.162.0
2020-01-10T07:23:54.1955866Z Author : Microsoft Corporation
2020-01-10T07:23:54.1955930Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2020-01-10T07:23:54.1956023Z ==============================================================================
2020-01-10T07:23:54.9006939Z [command]C:\windows\system32\chcp.com 65001
2020-01-10T07:23:54.9110635Z Active code page: 65001
2020-01-10T07:23:55.3752628Z [command]C:\hostedtoolcache\windows\dotnet\dotnet.exe publish d:\a\8\s\RINMVC.csproj --configuration $(BuildConfiguration) --output d:\a\8\a\s
2020-01-10T07:23:55.6992883Z Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
2020-01-10T07:23:55.6993590Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-01-10T07:23:55.6993774Z
2020-01-10T07:23:56.7768936Z d:\a\8\s\RINMVC.csproj : warning NU1701: Package 'System.Net.Http.Formatting.Extension 5.2.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
2020-01-10T07:23:56.7778950Z Restore completed in 48.65 ms for d:\a\8\s\RINMVC.csproj.
2020-01-10T07:23:57.1151368Z d:\a\8\s\RINMVC.csproj : warning NU1701: Package 'System.Net.Http.Formatting.Extension 5.2.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
2020-01-10T07:23:57.5687153Z C:\hostedtoolcache\windows\dotnet\sdk\3.1.100\Roslyn\Microsoft.CSharp.Core.targets(59,5): warning MSB3052: The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored. [d:\a\8\s\RINMVC.csproj]
2020-01-10T07:23:58.4874838Z Controllers\CompaniesController.cs(18,46): warning CS0169: The field 'CompaniesController.categoryViewModel' is never used [d:\a\8\s\RINMVC.csproj]
2020-01-10T07:24:01.5598101Z Could not find a part of the path 'd:\a\8\s\obj\$(BuildConfiguration)\netcoreapp3.1\Razor\Views\Cases\Add.cshtml.g.cs'.
2020-01-10T07:24:01.5599371Z at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
2020-01-10T07:24:01.5602238Z at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
2020-01-10T07:24:01.5602742Z at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
2020-01-10T07:24:01.5624368Z at System.IO.StreamWriter.ValidateArgsAndOpenPath(String path, Boolean append, Encoding encoding, Int32 bufferSize)
2020-01-10T07:24:01.5624829Z at System.IO.StreamWriter..ctor(String path)
2020-01-10T07:24:01.5625325Z at System.IO.File.WriteAllText(String path, String contents)
2020-01-10T07:24:01.5625688Z at Microsoft.AspNetCore.Razor.Tools.GenerateCommand.ExecuteCore(RazorConfiguration configuration, String projectDirectory, String tagHelperManifest, SourceItem[] sourceItems)
2020-01-10T07:24:01.5626021Z at Microsoft.AspNetCore.Razor.Tools.GenerateCommand.ExecuteCoreAsync()
2020-01-10T07:24:01.5626352Z at Microsoft.AspNetCore.Razor.Tools.CommandBase.ExecuteAsync()
2020-01-10T07:24:01.5731592Z C:\hostedtoolcache\windows\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.CodeGeneration.targets(150,5): error : rzc generate exited with code 1. [d:\a\8\s\RINMVC.csproj]
2020-01-10T07:24:01.6262880Z ##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
2020-01-10T07:24:01.6277867Z ##[warning]Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions.
Some commonly encountered changes are:
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2020-01-10T07:24:01.6278863Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\8\s\RINMVC.csproj
2020-01-10T07:24:01.6298381Z ##[section]Finishing: Publish
Yes I have resolved the issue as per #silent question that
Did you declare the variable BuildConfiguration ?
Due to testing purpose unfortunately I have deleted the variable (BuildConfiguration) into build definition under Variables section, so when i added the variable and save the definition its works as expected.
Thanks for the feedback #slient

xUnit tests fails when executed by Azure DevOps

I'm creating a very simple test project to experiment with various Azure DevOps CI/DI features. This project contains a solution with an ASP.NET Core website project, and an xUnit unit tests project. The unit tests runs correctly on my local machine (tested with the visual studio runner and with dotnet test, but I cannot make it work with an Azure build.
The output of the unit tests step in Azure is the following :
##[section]Starting: Test Assemblies
==============================================================================
Task : Visual Studio Test
Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version : 2.147.0
Author : Microsoft Corporation
Help : [More information](https://go.microsoft.com/fwlink/?LinkId=835764)
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : D:\a\1\s
VisualStudio version selected for test execution : latest
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : true
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Test selector : Test assemblies
Test assemblies : **\release\netcoreapp2.2\*test*.dll,!**\obj\**
Test filter criteria : null
Search folder : D:\a\1\s
Run settings file : D:\a\1\s
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
Rerun failed tests: false
VisualStudio version selected for test execution : latest
========================================================
======================================================
[command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" #D:\a\_temp\e481a311-390d-11e9-aa01-4f08eeab4c37.txt
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe
"D:\a\1\s\tests\ContosoUniversity.Tests\bin\Release\netcoreapp2.2\ContosoUniversity.Tests.dll"
"D:\a\1\s\tests\ContosoUniversity.Tests\bin\Release\netcoreapp2.2\xunit.runner.visualstudio.dotnetcore.testadapter.dll"
/logger:"trx"
/TestAdapterPath:"D:\a\1\s"
Starting test execution, please wait...
Test run will use DLL(s) built for framework .NETCoreApp,Version=v2.2 and platform X86. Following DLL(s) do not match framework/platform settings.
xunit.runner.visualstudio.dotnetcore.testadapter.dll is built for Framework 1.0 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.1 (64-bit .NET Core 4.6.27207.03)
[xUnit.net 00:00:04.36] Discovering: ContosoUniversity.Tests
[xUnit.net 00:00:04.43] Discovered: ContosoUniversity.Tests
[xUnit.net 00:00:04.44] Starting: ContosoUniversity.Tests
[xUnit.net 00:00:04.93] Finished: ContosoUniversity.Tests
Passed ContosoUniversity.Controllers.HomeControllerTest.Index_Renvoie_Le_Bon_Modele
Unable to find D:\a\1\s\tests\ContosoUniversity.Tests\bin\Release\netcoreapp2.2\xunit.runner.visualstudio.dotnetcore.testadapter.deps.json. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".
Results File: D:\a\1\s\TestResults\VssAdministrator_fv-az561_2019-02-25_14_59_22.trx
Total tests: Unknown. Passed: 1. Failed: 0. Skipped: 0.
Test Run Aborted.
Test execution time: 8.5546 Seconds
##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe' failed with exit code 1
##[error]VsTest task failed.
##[section]Async Command Start: Publish test results
Publishing test results to test run '1000118'
Test results remaining: 1. Test run id: 1000118
Published Test Run : https://orkeis-proj1.visualstudio.com/MyFirstProject_Test/_TestManagement/Runs#runId=1000118&_a=runCharts
##[section]Async Command End: Publish test results
##[section]Finishing: Test Assemblies
I'm failing to understand how I'm supposed to have that missing json file. The error suggests to install Microsoft.NET.Test.Sdk, but I do have it referenced in my project file :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>ContosoUniversity</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ContosoUniversity.csproj" />
</ItemGroup>
</Project>
So any tip about what I'm missing would be appreciated.
The problem was that the default file pattern to look for test assemblies (*test*.dll) also did include xUnit's core assemblies (named xunit.runner.visualstudio.dotnetcore.testadapter.dll), which confused the test system.
All I had to do to fix the issue is use a more specific pattern (like *tests.dll), or exclude all test adapter assemblies (!**/*testadapter.dll).
Update : The official xUnit documentation has been updated to help avoid this problem (https://xunit.net/docs/getting-test-results-in-azure-devops)
Thanks to #Shtong I was able to fix my xunit pipeline build.
This is my YAML file for future reference:
- task: VSTest#2
inputs:
testAssemblyVer2: |
**\bin\$(BuildConfiguration)\**\*tests*.dll
!**\obj\**
!**\xunit.runner.visualstudio.testadapter.dll
!**\xunit.runner.visualstudio.dotnetcore.testadapter.dll
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
otherConsoleOptions: '/platform:x64 /Framework:.NETCoreApp,Version=v3.1 /logger:console;verbosity="normal" '
I had a similar problem, that could be solved by the solution given by Shtong.
But in my case the cause was quite different, this is why I want to share it here.
In my scenario A.Tests project references B.Tests project because some test classes inherit from B.Tests classes. This caused B.Tests.dll to be copied to A.Tests.dll location causing the same hickup in vstest.
To get rid of the error I excluded B.Tests.dll from the A.Tests.dll folder by
!**\A.Tests\**\B.Tests.dll

Azure worker role gets published with the wrong service configuration

I'm trying to get the "publish to azure" functionality in VS2013 going for my worker-role cloud-service project.
The problem I'm having is that no matter what I change the service configuration settings to the application is always deployed with the Localservice configuration
My .azurePubxml:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AzureCredentials>{"ServiceManagementEndpoint":"https:\/\/management.core.windows.net\/","SubscriptionId":"redacted"}</AzureCredentials>
<AzureDeleteDeploymentOnFailure>False</AzureDeleteDeploymentOnFailure>
<AzureDeploymentLabel>MyWorkerRole</AzureDeploymentLabel>
<AzureDeploymentReplacementMethod>AutomaticUpgrade</AzureDeploymentReplacementMethod>
<AzureSlot>Staging</AzureSlot>
<AzureEnableRemoteDesktop>True</AzureEnableRemoteDesktop>
<AzureEnableWebDeploy>False</AzureEnableWebDeploy>
<AzureFallbackToDeleteAndRecreateIfUpgradeFails>False</AzureFallbackToDeleteAndRecreateIfUpgradeFails>
<AzureHostedServiceLabel>MyLabel</AzureHostedServiceLabel>
<AzureHostedServiceName>MyService</AzureHostedServiceName>
<AzureEnableIntelliTrace>False</AzureEnableIntelliTrace>
<AzureEnableProfiling>False</AzureEnableProfiling>
<AzureServiceConfiguration>Staging</AzureServiceConfiguration>
<AzureSolutionConfiguration>Staging</AzureSolutionConfiguration>
<AzureStorageAccountLabel>webstorage</AzureStorageAccountLabel>
<AzureStorageAccountName>webstorage</AzureStorageAccountName>
<AzureAppendTimestampToDeploymentLabel>True</AzureAppendTimestampToDeploymentLabel>
</PropertyGroup>
</Project>
As you can see, the AzureServiceConfiguration is set to Staging.
If i look at the output from the build I can see these lines:
Target "ResolveServiceConfiguration" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Windows Azure Tools\2.6\Microsoft.WindowsAzure.targets" from project "path-to.ccproj" (target "CoreResolveServiceModel" depends on it):
3> Task "Message"
3> Target Profile: Local
3> Task "Message"
3> Service Configurations: ServiceConfiguration.Staging.cscfg;ServiceConfiguration.Production.cscfg;ServiceConfiguration.Local.cscfg
3> Task "Message"
3> Looking for a service configuration file named: ServiceConfiguration.Local.cscfg
3> Task "FindInList"
3> Task "Message"
3> Source Service Configuration: ServiceConfiguration.Local.cscfg
3> Task "Message"
3> Target Service Configuration: bin\Staging\ServiceConfiguration.cscfg
The end-result is that the ServiceConfiguration.Local.cscfg is used in the deployment instead of ServiceConfiguration.Staging.cscfg.
What does work though is to change the Service Configuration setting to staging under Development->Run/debug.
But this setting controls which configuration file is used when I run the app locally, so naturally I don't want to mess with it.
Also, if I use the Project->Package... option and choose staging I get the correct package and the correct config file generated.
I've also tried bulding manually with msbuild from commandline, works great as well.
Tried updating to azure sdk 2.6 in hopes that it would solve it, but no difference.
Should also say that I have this working in my web-role project. But for external reasons I had to split the worker-role to its own cloud project.
Update Some more info, I took a another closer look at the build log and found this:
1>------ Build started: Project: MyProject, Configuration: Debug Any CPU ------
1>Build started 6/5/2015 5:15:03 PM.
1>Building with tools version "12.0".
1>Target "_CheckForInvalidConfigurationAndPlatform" in file "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets" from project "path_to_project.csproj" (entry point):
1>Task "Error" skipped, due to false condition; ( '$(_InvalidConfigurationError)' == 'true' ) was evaluated as ( '' == 'true' ).
1>Task "Warning" skipped, due to false condition; ( '$(_InvalidConfigurationWarning)' == 'true' ) was evaluated as ( '' == 'true' ).
1>Using "Message" task from assembly "Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>Task "Message"
1> Task Parameter:Text=Configuration=Debug
1> Task Parameter:Importance=Low
1> Configuration=Debug
So it seems that neither
<AzureServiceConfiguration>Staging</AzureServiceConfiguration>
<AzureSolutionConfiguration>Staging</AzureSolutionConfiguration>
from the .azurePubxml are actually being used as input to the build script.
It all seems to boil down to, where is the Publish to Azure function pulling its parameters from, if not from the .azurePubxml file?
Never got this working fully in VS2013 but now I've gone up to VS2015 and publish to Azure works as expected again.

MSBuild error executing target WebDirectoryCreate

I'm trying to use the WebDirectoryCreate task from the MSBuildCommunityTasks to create my virtual directory with MSBuild but it throws an Index was out of range error.
Here's the relevant part of my build script:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
...other build targets working ok...
<Target Name="Deploy">
<RemoveDir Directories="$(DeploymentFolder)$(VerRevision)" ContinueOnError="true" />
<ItemGroup>
<DeploymentFiles Include="$(PublishOutputFolder)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(DeploymentFiles)" DestinationFolder="$(DeploymentFolder)$(VerRevision)\%(RecursiveDir)" />
<WebDirectoryDelete VirtualDirectoryName="$(VirtualDirectory)$(VerRevision)" ContinueOnError="true" />
<WebDirectoryCreate VirtualDirectoryName="$(VirtualDirectory)$(VerRevision)" VirtualDirectoryPhysicalPath="$(DeploymentFolder)$(VerRevision)" />
</Target>
And here's the corresponding output:
Deleting virtual directory 'MyApp283' on 'localhost:80'.
MSBUILD : warning : The system cannot find the path specified. (Exception from HRESULT: 0x80070003) [D:\build\MyApp\Build.xml]
The previous error was converted to a warning because the task was called with ContinueOnError=true.
Build continuing because "ContinueOnError" on the task "WebDirectoryDelete" is set to "true".
Creating virtual directory named MyApp283 on localhost:
D:\build\MyApp\Build.xml(50,5): error : Index was out of range. Must be non-negative and less than the size of the collection.
D:\build\MyApp\Build.xml(50,5): error : Parameter name: index
Done Building Project "D:\build\MyApp\Build.xml" (default targets) -- FAILED.
Build FAILED.
I have checked the import is correct by adding the virtual directory manually and running the build. In this case the WebDirectoryDelete task corrcetly deletes the virtual directory but WebDirectoryCreate throws the same error.
I'm executing the build using MSBuild from a simple batch file. All tasks before this one execute just fine. OS is Windows Server 2008 R2 Enterprise Edition SP1.
Can anyone give me any clues? SO and Google threw up one single link with no answer.

Resources