projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.12k stars 652 forks source link

Deployment fails with new csproj format and 1.0.0-preview3-004056 #2236

Closed colltoaction closed 7 years ago

colltoaction commented 8 years ago

I have a project I just converted from project.json to csproj. I read the latest issues and tried to set up the environment with a global.json containing:

"sdk": {
    "version": "1.0.0-preview3-004056"
}

I also git clean -xdf'd the repo and deleted deploy.cmd to have a fresh environment. When I deploy packages are restored fine but it seems msbuild isn't finding them. E.g. my controllers can't find aspnet's types:

remote: Generating deployment script.
remote: Running deployment command...
remote: Handling .NET Console Application deployment.
remote: MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
remote: All packages listed in packages.config are already installed.
remote: Controllers\Controller1.cs(1,28): error CS0234: The type or namespace name 'Authorization' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller1.cs(2,28): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller1.cs(3,28): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller1.cs(4,17): error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller2.cs(1,28): error CS0234: The type or namespace name 'Authorization' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller2.cs(2,28): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller2.cs(3,28): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller2.cs(4,17): error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller3.cs(1,28): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]
remote: Controllers\Controller4.cs(1,28): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [D:\home\site\repository\XXX\XXX.csproj]

The name of my Web App ends with gs and is next to dummy321.

Thanks!

davidebbo commented 8 years ago

@tinchou the Kudu script generator doesn't yet know how to handle Preview3, but you should be able to use a custom deployment script. The key is to use 'dotnet restore' instead of 'nuget restore' and 'dotnet publish' instead of 'msbuild'. See sample here.

We will fix Kudu to handle this soon.

colltoaction commented 8 years ago

Awesome! I'll use my own script for now, and keep us posted with any updates about built-in support :)

davidebbo commented 8 years ago

That first sample I pointed to was non-VS created. Here is a sample with a VS 2017 RC project: https://github.com/davidebbo-test/MvcCoreVS2017RC

watashiSHUN commented 7 years ago

@tinchou, the new projectkudu/KuduScript#56 is out you can now use SCM_SCRIPT_GENERATOR_ARGS=--aspNetCore "csproj file path" --solutionFile "solution file path" instead of providing a deploy.cmd, please refer to this documentation for usage

colltoaction commented 7 years ago

Just tried it but I'm facing an issue with an old project. YYY is the old (ASP.NET 4) one and XXX is the one I'm trying to deploy (ASP.NET Core 1).

I didn't specify a solution file, but just --aspNetCore "XXX\XXX.csproj"

This is the error message:

remote: Generating deployment script.
remote: Project file path: .\XXX\XXX.csproj
remote: Generated deployment script files
remote: Running deployment command...
remote: Handling ASP.NET Core Web Application deployment.
remote: D:\home\site\repository\YYY\YYY.csproj(824,3): error MSB4019: The imported project "D:\Program Files (x86)\dotne
t\sdk\1.0.0-preview3-004056\Extensions\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" wa
s not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
remote: ...................................................................................
remote: Failed exitCode=1, command=dotnet restore
remote: An error has occurred during web site deployment.
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.

UPDATE

I created a new solution file removing the old project (not actually needed for this deployment). I also added the --solutionFile switch, but dotnet restore stills fails because it doesn't use the project name. The flag works fine because the log now shows:

remote: Project file path: .\XXX\XXX.csproj
remote: Solution file path: .\ZZZ.sln
davidebbo commented 7 years ago

@tinchou can you please provide a repro, including both the test repo and the exact app setting you set?

It worked fine for me using:

colltoaction commented 7 years ago

Step 4: add an empty MVC 4 project.

Repro: https://github.com/tinchou/KuduRepro

davidebbo commented 7 years ago

That's odd. @piotrpMSFT / @vijayrkn / @rrelyea any idea what's going on here? I can actually repro on my local machine by simply calling dotnet restore at the root of the solution. It fails with:

D:\gitapps\MvcCoreVS2017RC\WebApplication1\WebApplication1.csproj(213,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.0-preview3-004056\Extensions\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

So it's looking for Extensions\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets in the dotnet sdk folder, and there is no such file.

Maybe in its current alpha state, the tooling doesn't allow mixing Core and non-Core in the same solution?

colltoaction commented 7 years ago

It actually doesn't matter if the csproj is in the solution or not.

Also, my local dotnet allows me to specify a sln file but not the one on Azure

On Fri, Nov 25, 2016, 00:40 David Ebbo notifications@github.com wrote:

That's odd. @piotrpMSFT https://github.com/piotrpMSFT / @vijayrkn https://github.com/vijayrkn / @rrelyea https://github.com/rrelyea any idea what's going on here? I can actually repro on my local machine by simply calling dotnet restore at the root of the solution. It fails with:

D:\gitapps\MvcCoreVS2017RC\WebApplication1\WebApplication1.csproj(213,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.0-preview3-004056\Extensions\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

So it's looking for Extensions\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets in the dotnet sdk folder, and there is no such file.

Maybe in its current alpha state, the tooling doesn't allow mixing Core and non-Core in the same solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/projectkudu/kudu/issues/2236#issuecomment-262875075, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeg9A0_pIusRUQXfMBVpCl6xFXiiLfgks5rBliVgaJpZM4K3YNZ .

jsgoupil commented 7 years ago

2017 RC template projects don't deploy on Azure either.

  1. Create a project ASP.NET Core Web Application (.NET Framework)
  2. Commit to git
  3. Configure Azure deployment
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Console Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
Controllers\HomeController.cs(5,17): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Program.cs(6,17): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(5,17): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(6,17): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(7,17): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(8,17): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(9,17): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Controllers\HomeController.cs(9,35): error CS0246: The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Controllers\HomeController.cs(11,16): error CS0246: The type or namespace name 'IActionResult' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Controllers\HomeController.cs(16,16): error CS0246: The type or namespace name 'IActionResult' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Controllers\HomeController.cs(23,16): error CS0246: The type or namespace name 'IActionResult' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Controllers\HomeController.cs(30,16): error CS0246: The type or namespace name 'IActionResult' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(25,16): error CS0246: The type or namespace name 'IConfigurationRoot' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(28,39): error CS0246: The type or namespace name 'IServiceCollection' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(35,31): error CS0246: The type or namespace name 'IApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(35,56): error CS0246: The type or namespace name 'IHostingEnvironment' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(35,81): error CS0246: The type or namespace name 'ILoggerFactory' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Startup.cs(15,24): error CS0246: The type or namespace name 'IHostingEnvironment' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\WebApplication1\src\WebApplication1\WebApplication1.csproj" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="D:\local\Temp\8d4194d4cd2ab8f\app_data\jobs\continuous\deployedJob";UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository\WebApplication1\\"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\59.51122.2559\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
colltoaction commented 7 years ago

@jsgoupil you didn't follow @watashiSHUN's instructions properly.

When you do that the deployment will output Handling ASP.NET Core Web Application deployment. Run git clean -xfd and remove the deployment files at scm if you don't see any changes with the SCM_SCRIPT_GENERATOR_ARGS setting.

jsgoupil commented 7 years ago

@tinchou Indeed I did not read all the pages and comments to actually deploy a simple application on Azure.

Anyway, it doesn't work.

You can't expect people who want to deploy on Azure to come read this thread or even know about the Kudu project. There are too many steps to get up and running with .NET Core.

image

--aspNetCore "WebApplication1\src\WebApplication1\WebApplication1.csproj" --solutionFile "WebApplication1\WebApplication1.sln"

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
Failed exitCode=1, command=dotnet restore
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\59.51122.2559\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

Now... I moved the SLN file to the root of the directory... and it starts working.
That's way too constraining. Can't you support a path in --solutionFile

colltoaction commented 7 years ago

Well, MSBuild support for .NET Core is alpha, so I think it's great that we already have support in Kudu. This thread is to discuss bugs in this deployment option, so welcome and thanks for reporting!

I too think that is too constraining. I think the sln path that is specified should be passed on to dotnet restore.

davidebbo commented 7 years ago

Indeed, this is a point in time thing. We already simplified things from requiring a full custom script to only needed this app setting. Next step is to make it fully automatic, and that's in the work.

martinnormark commented 7 years ago

I'm seeing a similar issue as @jsgoupil

I forked the https://github.com/davidebbo-test/MvcCoreVS2017RC by @davidebbo to https://github.com/martinnormark/MvcCoreVS2017RC and added an extra solution file to the root in https://github.com/martinnormark/MvcCoreVS2017RC/commit/ba930150cb59ba3695bd618bace34c74d5aa033f

The error I'm getting is this:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.
Failed exitCode=1, command=dotnet restore
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\59.51122.2559\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
watashiSHUN commented 7 years ago

@martinnormark, I just tried your repo on my local machine and it worked, your issue is about multiple solution files which has been brought up by @tinchou couple days ago:

I too think that is too constraining. I think the sln path that is specified should be passed on to dotnet restore.

and the fixes are made two days ago: this commit, it's being reviewed right now

if your project really needs two solution files right now, you can always go back to the custom deploy.cmd: and specify dotnet restore oneOfSeveralSolutionFilePath

watashiSHUN commented 7 years ago

the latest Kudu is deployed to Azure

@martinnormark your repo should work as is. custom deploy.cmd is no longer required

@tinchou @jsgoupil SCM_SCRIPT_GENERATOR_ARGS is also no longer needed to deploy a regular dotnet preview3 projects in azure (unless its a special case, for example: repository with multiple solution files)

davidebbo commented 7 years ago

Closing since the mainline scenario should now directly work. If you find specific repos that don't quite work, please open separate issues to help tracking. Thanks!

colltoaction commented 7 years ago

I can confirm that after removing the non-Core projects from my solution everything works as expected automagically :).

Thanks!