I'm currently working on an ASP.NET MVC application built in .Net5 that utilizes TypeScript files and includes NuGet package references for the following:
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.113" />
Within my project structure, I have:
- A folder named
node-modules
(not pushed to Azure Devops) - bundleconfig.json
- gulpfile.js
- libman.json
- package.json (+ package-lock.json)
The contents of my package.json
are as follows:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"gulp": "4.0.2",
"del": "5.1.0",
"@types/bootstrap": "4.5.0",
"@types/google.visualization": "0.0.53",
"@types/jquery": "3.5.1",
"@types/jqueryui": "1.12.13",
"@types/jquery.datatables": "1.10.36",
"@types/jquery.ui.datetimepicker": "0.3.29"
}
}
While compiling in Visual Studio 2019, everything functions correctly but I encountered a warning in the Build Output:
Package restore on project open is disabled. Change the npm package management settings in Project Properties to enable restore on project open.
To resolve this, I set "Restore On Project Save" to true
, which added the following snippet to my csproj file:
<ProjectExtensions><VisualStudio><UserProperties appsettings_1qaf_1json__JsonSchema="https://gitpod.io/schemas/gitpod-schema.json" NpmRestoreOnProjectOpen="True" /></VisualStudio></ProjectExtensions>
After pushing the changes to Azure DevOps, I encountered errors when building with the hosted agent:
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
clean: true
This resulted in the error message:
##[error]MyApp\Scripts\MyTypeScript.ts(13,9): Error TS2581: Build:Cannot find name '$'. Do you need to install type definitions for jQuery? Try
npm i @types/jquery
.
It appears that the hosted agent is not retrieving the necessary types. I suspect adjustments are needed in my YAML file, but I am unsure of the correct approach...