GIT based asp.net web app fails to deploy to Azure with typescript compile error - asp.net

I have this asp.net (4.6.2) web application which compiles and runs fine on my local machine.
The project is in a Git repo in VSTS.
I want this site deployed to Azure web sites. So I make a Webapp and set the deployment option to my VSTS Git repo.
This will automatically trigger a deployment... which fails.. with this error:
All packages listed in packages.config are already installed.
D:\home\site\repository\FormBuilder\Scripts\typings\knockout\knockout.d.ts(335,13): error TS1110: Build: Type expected. [D:\home\site\repository\FormBuilder\FormBuilder.csproj]
D:\home\site\repository\FormBuilder\Scripts\typings\knockout\knockout.d.ts(338,11): error TS1109: Build: Expression expected. [D:\home\site\repository\FormBuilder\FormBuilder.csproj]
D:\home\site\repository\FormBuilder\Scripts\typings\knockout\knockout.d.ts(339,1): error TS1128: Build: Declaration or statement expected. [D:\home\site\repository\FormBuilder\FormBuilder.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\FormBuilder\FormBuilder.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d3e9219d2f6f3b";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository.\"
An error has occurred during web site deployment.
It looks to me like it's compiling my .d.ts files. Don't know why..VS2015 does not do that.
I tried to exclude this file in a tsconfig but that does not work.
How can I make this build succeed?

So the problem is that the Azure build machine is not equipped with typescript 2.0 (yet) and knockout.d.ts uses a 2.0 syntax for something. See the comments below the question.
GitHub issue here

You need to compile type script files before deploying to azure. In deploy.cmd file on azure you can add this code to Compile TypeScript right after the npm packages are installed.
echo Transpiling TypeScript in %DEPLOYMENT_TARGET%...call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -p "%DEPLOYMENT_TARGET%"
You can find the deploy.cmd file on KUDU in site->deployments->tools section.

Related

Azure Pipelines Xamarin.Forms iOS build fails with error MSB4057: The target "_IsProjectRestoreSupported" does not exist in the project

We have Xamarin.Forms solution with iOS and UWP projects. We use Azure pipelines to build the iOS project. Until yesterday everything was working fine.
Now the build fails at the NuGet Restore step with the error:
##[error]The nuget command failed with exit code(1) and error(/Users/runner/work/1/s/"MyProjectName.UWP".csproj : error MSB4057: The target "_IsProjectRestoreSupported" does not exist in the project.
We can see that the problem occurs when trying to restore NuGet packages for the UWP project on the Mac OS build host.
Image: macOS-11
Workaround will be to exclude it from the solution, but we are using it for testing purposes and this is not a good option for us.
We had the same problem yesterday for our iOS (macos-11) and Android (macos-10.15) Pipelines.
The issue 21180 for mono seems to be the root cause, which is also referenced in a pull request to update the mono version for MacOs virtual environments. Regarding to this workflow test we gave msbuild a chance, and it works.
Solution:
Instead of NuGet restore we use directly MSBuild.
- task: MSBuild#1
inputs:
solution: 'App.sln'
configuration: 'Release'
msbuildArguments: /t:restore
Looking at the log file, MSBuild ignores the UWP project. That is the behavior that NuGet had with the older mono version 6.12.0.125. Ignoring the UWP-Project is no problem, because it can only be build on windows environments.
Project "/Users/runner/work/1/s/App.sln" on node 1 (Restore target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Release|Any CPU".
/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/NuGet.targets(315,5): warning : Skipping restore for project '/Users/runner/work/1/s/App/App.UWP/App.UWP.csproj'. The project file may be invalid or missing targets required for restore. [/Users/runner/work/1/s/App.sln]
Some additional information:
The NuGet restore task uses msbuild to find all referenced packages. If that fails, it will use the packages.config file as fallback, the pipeline step will not fail.
Instead we got an error in the build steps for Android & iOS:
error NETSDK1004: Assets file
'/Users/runner/work/1/s/../obj/project.assets.json' not found. Run a
NuGet package restore to generate this file.
Updated Answer
This can be resolved using MSBuild task instead, as the collogues mentioned below.
However, in my case this still lead to the same error. After investigating the pipeline. The root cause has been identified:
Both in MSBuild#1 and XamariniOS#2 tasks
you should target the specific iOS Project and not the solution file, like so:
"
- task: MSBuild#1
inputs:
solution: 'PathToIosProject/myproject.iOS.csproj'
configuration: '$(BuildConfiguration)'
msbuildArguments: /t:restore
" - task: XamariniOS#2
inputs:
solutionFile: PathToIosProject/myproject.iOS.csproj'
configuration: '$(BuildConfiguration)'
packageApp: true
signingIdentity: $(APPLE_CERTIFICATE_SIGNING_IDENTITY)
Old Answer
We have managed to resolve the issue. The root cause of it seems to be an update to the mono framework in the MacOS pipeline build agent.
In order to fix it, we need a script for downloading and installing an older version of the mono framework as a first step of the build pipeline like so:
link to the pipeline tasks photo
This is the code of the bash scrip used in the task:
#!/bin/bash
set -ex
MONO_MACOS_PKG_DOWNLOAD_URL='https://download.mono-project.com/archive/6.12.0/macos-10-universal/MonoFramework-MDK-6.12.0.100.macos10.xamarin.universal.pkg'
mkdir -p /tmp/mono-install
cd /tmp/mono-install
mono --version
wget -q -O ./mono-installer.pkg "$MONO_MACOS_PKG_DOWNLOAD_URL"
sudo installer -pkg ./mono-installer.pkg -target /
mono --version
ls -alh /Library/Frameworks/Mono.framework/Versions/Current

TeamCity - Building dotnet core web api project using cake script

Running Cake Build script on my local machine works fine but when same script is run on TeamCity, the following error appears: Nuspec file does not exist in package.
Any idea what could have caused this error?
I spent two days due to this error
On dotnet build --configuration Release in TeamCity PowerShell, always got this error
error NU5000: Nuspec file does not exist in package
After deleting this folder, everything worked C:/Users/teamcity_user/.nuget
I add an additional step on top of my build steps which is a command line custom script
dotnet nuget locals --clear all

Bitbucket pipelines: The type or namespace name could not be found

I'm hoping someone can help me out. Thanks!
I'm trying to deploy my dotnet core 2.0 API
When I try and build the project with bitbucket pipelines I get multiple errors finding references. It does restore the project successfully.
However the project builds successfully on my laptop.
folder structure:
/API
/Controllers
/Migrations
/Models
/Services
API.csproj
Program.cs
Startup.cs
bitbucket-pipelines.yml
pipelines:
default:
- step:
image: microsoft/dotnet
name: Check if it builds
script:
- cd API
- dotnet build
example error:
Services/MyService.cs(18,29): error CS0246: The type or namespace name 'IRepository<>' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/API/API.csproj]
Note I have the latest version of dotnet, same as I'm using in bitbucket pipelines. I have checked via running dotnet --info
Finally i've figured out what was the cause of this issue. I feel really silly for not figuring this out sooner.
My git repository was somehow setup with ignorecase = true.
I have switched it to false (which will prevent this issue in the future).
This means that I can have two of the same files or folders.
I had renamed a folder to a different case.
My repo had
API/
API.csproj
and
api/
api.csproj
My Mac couldn't allow for both so I only saw one folder and one project on my local machine.
To fix this, I had to git rm -r --cached api
This deleted the duplicate folder
I had the project file as a duplicate as well so used git rm -f api.csproj to remove the file from the repository.
Then git pull to bring those changes into my local master branch.

VSTS msdeploy.exe error: ERROR_USER_NOT_AUTHORIZED_FOR_CONTENTPATH

I'm trying to create a release definition inside VSTS to deploy my ASP.NET Core 2.0 app on my production server.
I'm using the MSDeployAllTheThings extension: https://marketplace.visualstudio.com/items?itemName=rschiefer.MSDeployAllTheThings
I'm able to deploy inside Visual Studio using the same configuration...
VSTS Config (not working)
VSTS Error
Visual Studio Config (working)
Do you guys have any ideas how to do that?
I had the same problem with deployment to smarterasp.net and was able to setup things for Web Deploy:
Your Dotnet Build task could create deployment package with necessary files like [YourProject].deploy.cmd, [YourProject].zip and etc. For this you could use next Arguments in your Build Task:
--configuration $(BuildConfiguration) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
Add "Batch script" task and set path to your [YourProject].deploy.cmd in Path field and also in your Arguments:
/y /m:$(SmarterAspNet.PublishUrl) -AllowUntrusted /u:$(SmarterAspNet.UserName) /p:$(SmarterAspNet.Password) /a:Basic "-setParam:name='IIS Web Application Name',value='$(SmarterAspNet.SiteName)'" -enableRule:AppOffline
With this two main DevOps tasks I was able to deploy my app to smarterasp.net
About MSDeployAllTheThings task: I removed it because it is not needed for me anymore
Not familiar with smarterasp.net. But this should be an issue with that site.
If you run the same msdeploy command from your local machine manually, you will get the same error message. We didn't see this error when use the same command to deploy to some other host instead of smarterasp.net. And if you add "-verbose" in the command, you will get a more detailed information which indicates that the command failed to adding the virtual path:
When you deploy your project from VS, it use the manifest file and source folder directly rather than "package" method. So you'd either contact smarterasp.net for help or use the same deploy method as Visual Studio or some other deploy method like FTP.

How do I git deploy an .fsproj based f# project to azure?

I have an ASP.NET core application that I've been auto-deploying to an azure app service on commit to a git repo. It worked fine as a project.json type project.
I've converted my project.json to myproject.fsproj and it builds and runs locally. On comitting the .fsproj to git, the deployment was triggered, but it failed with the activity log containing one line: 'D:\home\site\repository\myproject.fsproj' is not a deployable project.
I guess it's an issue with the default kudu deployment script? Does anyone know how to sort this out, or do I need to submit an issue/RFC to the kudu guys?
UPDATE
I generated the original .fsproj using:
dotnet new mvc --language f# --framework netcoreapp1.0
I've since made changes to it, so I will try to do a minimal case later tonight.
Turns out that the default deployment in azure wouldn't deal with this.
Following the answer on Kudu Deployment Script for ASP.NET Core 1.0, I generated a custom deployment script using:
npm install -g kuduscript
kuduscript -y --aspNetCore myproject.fsproj
Added the resulting deploy.cmd along with a .deployment:
[config]
command = deploy.cmd
A deployment triggered by a push to git works as expected now.

Resources