Reputation: 26374
I have a Visual Studio solution housing an Azure Cloud Service with the following projects:
Where the Tests
project is a standard MSTest project that contains unit tests for the business logic in the CloudServiceRole
project.
The code is stored in Visual Studio Online and I have hooked up the automated CI build deployment that Azure offers. When I check in code, my staging deployment of the cloud service is automatically updated. However, the Tests project is never even built during the CI builds! This, of course, means that no unit tests run during the build as the "run unit tests" part of the build process finds no assemblies with tests.
My goal is to change this so the tests project is built and all the unit tests executed.
Looking at the MSBuild arguments that the CI deployment process uses, it appears that only the CloudService:Publish
target is executed. The CloudService
project has no dependency on the Tests
project so MSBuild never even builds the latter.
What I have tried
I cannot manually add a CloudService->Tests
dependency because when I add dependencies on projects that are not Cloud Service Role projects, I get an error during build (The item "C:\a\src\MyProject\Tests\Tests.csproj" in item list "ProjectReferenceWithConfiguration" does not define a value for metadata "Name".
) and I cannot add a CloudServiceRole->Tests
dependency because that would make a circular dependency.
Instructing MSBuild to build the full solution by manually adding a /t:Build
parameter resulted in yet another error: C:\a\bin\ServiceDefinition.csdef: Need to specify the physical directory for the virtual path 'Web/' of role Web.
Adding the Tests
project as a separate build target, alongside the solution, results in the tests getting built! However, at the same time, it disables the Continuous Deployment functionality: More than one solution found. Continuous Deployment skipped.
Trying to make a fake Cloud Service Role project that references the Tests
project but has zero instances configured results in a build error: WAT100: The following roles 'Tests.FakeRole' have an instance count of 0. Instance count of 0 is not supported in deployments to Microsoft Azure
. Attempting to disable this validation results in a build error due to a defect in the Azure SDK.
Upvotes: 3
Views: 1076
Reputation: 1881
You need to run a Build
and a Publish
separately. I ran into the same problem on my VSO (now VSTS) project and this fixed it. This happens because your cloud service doesn't depend on your unit test project.
1) Visual Studio Build (or MSBuild) action with arguments /t:Build
(clean here)
2) Visual Studio Build (or MSBuild) action with arguments /t:Publish
(do not clean here)
Note: I had to run these actions separately (not /Build;Publish
) otherwise I got an error about the cloud service entry point.
Pieced this together from this question and from here and here.
Upvotes: 1
Reputation: 26374
One workaround that appears to bring results is to add a pre-MSBuild script to the build definition and explicitly build the Tests project in that script.
:: This is used as a pre-build script in Continuous Deployment builds because on their own, they do not build the Tests project.
"c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" %~dp0\..\..\Tests\Tests.csproj /t:Build /p:Configuration=Debug;Platform=AnyCPU;OutDir="%~dp0\..\..\..\..\bin\\"
It appears to do the job, although I am not sure what side-effects I should be aware of. My main concern is that the binaries from this build go into the same directory as the binaries from the Cloud Service build - is there perhaps some possibility of conflict here?
Upvotes: 0