英文:
Azure DevOps Build error NETSDK1005: Assets file doesn't have a target for net7.0
问题
我已经在Visual Studio 2022中使用"ASP.NET Core Web API"模板创建了新项目。这是一个简单的API项目,除了在"program.cs"中移出了Swagger之外,没有对模板进行任何更改,以便在部署应用程序到"Azure App Service"时可以使用Swagger。
我正在使用Azure DevOps,并且遇到了需要解决的构建错误。
错误信息:
##[error]C:\Program Files\dotnet\sdk\7.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: "D:\a\1\s\MyApp.Web.APIs\obj\project.assets.json"文件没有针对"net7.0"的目标。请确保已运行还原操作,并在项目的TargetFrameworks中包括"net7.0"。
在"project.assets.json"文件中,我可以看到"TargetFrameworks"设置为"7.0"。对于这个问题,我不太确定我缺少什么。
英文:
I have created new project using template ASP.NET Core Web API
in Visual Studio 2022. This is simple API project and have not change anything in the template except in program.cs'; moved out swagger outside the
if (app.Environment.IsDevelopment())so that I can use swagger when deploy application in
Azure App Service'
app.UseSwagger();
app.UseSwaggerUI();
I am using Azure DevOps and getting build error which I need to resolve
error
##[error]C:\Program Files\dotnet\sdk.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: Assets file 'D:\a\s\MyApp.Web.APIs\obj\project.assets.json' doesn't have a target for 'net7.0'. Ensure that restore has run and that you have included 'net7.0' in the TargetFrameworks for your project.
In project.assets.json
file, I can see TargetFrameworks
is set to 7.0
not really sure, what I am missing from the puzzle.
答案1
得分: 2
根据官方文档,NuGet版本应该高于5.8。
我们也遇到了相同的错误。我们所做的是
- 添加一个NuGet安装程序任务作为NuGet还原的先前步骤(如果您在DevOps中使用经典编辑器定义流水线,已经包括在内)。
- 在任务中,您可以提及NuGet的版本,我们提到的版本是5.8
英文:
According to the official documentation, the NuGet version should be higher than 5.8.
We got the same error too. What we did was
- Add a NuGet Installer task as a previous step to NuGet restore (already included if you are using the classic editor in DevOps to define the pipeline).
- In the task, you can mention the version of NuGet, which we mentioned as 5.8
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论