Search code examples
visual-studio-2015asp.net-coretfsbuildazure-devopsdnx

Building ASP.NET 5 project in VSO


I cannot get VSO to build ASP.NET 5 projects. There seems to be an issue getting the packages.

Build steps in VSO:

VSO Build Steps

I have the project building in VS 2015 and have "Restore NuGet Packages" checked.

Build console output:

******************************************************************************
Starting task: Build solution $/Root/TestApi/Development/TestApi.sln
******************************************************************************
Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\tasks\VSBuild\1.0.13\VSBuild.ps1
C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe "C:\a\dce2e497\Root\TestApi.sln" /nologo /m /nr:false /fl /flp:"logfile=C:\a\dce2e497\Root\TestApi.sln.log" /dl:CentralLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="C:\a\dce2e497\staging" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="14.0"
Build started 8/2/2015 11:21:29 AM.
     1>Project "C:\a\dce2e497\Root\TestApi.sln" on node 1 (default targets).
     1>ValidateSolutionConfiguration:
         Building solution configuration "release|any cpu".
     1>Project "C:\a\dce2e497\Root\TestApi.sln" (1) is building "C:\a\dce2e497\Root\TestApi.Api\TestApi.Api.xproj" (2) on node 1 (default targets).
     2>PrepareForBuild:
         Creating directory "..\artifacts\bin\TestApi.Api\".
         Creating directory "..\artifacts\obj\TestApi.Api\Release\".
       PreComputeCompileTypeScript:
         C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\tsc.exe  --noEmitOnError COMPUTE_PATHS_ONLY
       CompileTypeScript:
       Skipping target "CompileTypeScript" because it has no outputs.
       CoreCompile:
         C:\Users\buildguest\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta6\bin\dnx.exe --appbase "C:\a\dce2e497\Root\TestApi.Api" "C:\Users\buildguest\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta6\bin\lib\Microsoft.Framework.PackageManager\Microsoft.Framework.PackageManager.dll" pack "C:\a\dce2e497\Root\TestApi.Api" --configuration Release --out "..\artifacts\bin\TestApi.Api"
         Microsoft .NET Development Utility CLR-x86-1.0.0-beta6-12256
         Building TestApi.Api for DNX,Version=v4.5.1
           Using Project dependency TestApi.Api 1.0.0
             Source: C:\a\dce2e497\Root\TestApi.Api\project.json
           Unable to resolve dependency Microsoft.AspNet.Server.IIS 1.0.0-beta6
    TestApi.Api\Startup.cs(5,17): Error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
     2>C:\a\dce2e497\Root\TestApi.Api\Startup.cs(5,17): DNX,Version=v4.5.1 error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\a\dce2e497\Root\TestApi.Api\TestApi.Api.xproj]
TestApi.Api\Startup.cs(6,17): Error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
     2>C:\a\dce2e497\Root\TestApi.Api\Startup.cs(6,17): DNX,Version=v4.5.1 error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\a\dce2e497\Root\TestApi.Api\TestApi.Api.xproj]

Note that this is specific to NuGet package restore. Refer to my answer for the fix.


Solution

  • I used the following step to install DNVM, DNX and to call dnu restore for each project.json file found in src:

    # bootstrap DNVM into this session.
    &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
    
    # load up the global.json so we can find the DNX version
    $globalJson = Get-Content -Path $PSScriptRoot\global.json -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
    
    if($globalJson)
    {
        $dnxVersion = $globalJson.sdk.version
    }
    else
    {
        Write-Warning "Unable to locate global.json to determine using 'latest'"
        $dnxVersion = "latest"
    }
    
    # install DNX
    # only installs the default (x86, clr) runtime of the framework.
    # If you need additional architectures or runtimes you should add additional calls
    # ex: & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
    & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
    
     # run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
    Get-ChildItem -Path $PSScriptRoot\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }
    

    Refer to this MSDN post.