首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Nuget PackageReference在一个解决方案中找到,但在我自己的解决方案中找不到

Nuget PackageReference在一个解决方案中找到,但在我自己的解决方案中找不到
EN

Stack Overflow用户
提问于 2022-08-12 12:24:33
回答 1查看 331关注 0票数 -1

前标题:

找不到"GenerateFileFromTemplate“任务 .NET项目模板- GeneratedContent .csproj.in文件转换

麻烦的包是Microsoft.DotNet.Build.Tasks.Templating.

我创建了一个包含多个git-储存库项目模板的.NET。在Visual中打开时,VS在向模板项目中添加更多文件时具有糟糕的性能。结果发现,这是由于我的模板的项目文件具有.csproj扩展名。为此,我将所有模板csproj文件的扩展名更改为csproj.in

因此,我需要添加一个msbuild任务,将这个.csproj.in转换为.csproj。在互联网上有几个例子:

在上述示例中,项目中没有nuget.config

csproj文件包含一个<GeneratedContentProperties><GeneratedContent>部分:

代码语言:javascript
运行
复制
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <GeneratedContentProperties>
      DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework);
    </GeneratedContentProperties>
  </PropertyGroup>

  <ItemGroup>
    <GeneratedContent Include="Angular-CSharp.csproj.in" OutputPath="content/Angular-CSharp/Company.WebApplication1.csproj" />
    <GeneratedContent Include="React-CSharp.csproj.in" OutputPath="content/React-CSharp/Company.WebApplication1.csproj" />
  </ItemGroup>
</Project>

.csproj.in文件引用GeneratedContentProperties

代码语言:javascript
运行
复制
<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
        ...
    </PropertyGroup>
    ...
</Project>

我尝试在此承诺中将相同的文件应用于我的项目,但在构建该项目时仍会遇到以下错误:

代码语言:javascript
运行
复制
dotnet build --configuration Release
MSBuild version 17.3.0+92e077650 for .NET
  Determining projects to restore...
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(152,5): warning NETSDK1023: A PackageReference for 'Microsoft.DotNet.Build.Tasks.Templating' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.
IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj]
...
  All projects are up-to-date for restore.
...
C:\repos\MintPlayer.AspNetCore.Templates\eng\GenerateContent.targets(27,3): error MSB4036: The "GenerateFileFromTemplate" task was not found. Check the following:
    1.) The name of the task in the project file is the same as the name of the task class.
    2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
    3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files\dotnet\sdk\6.0.400" directory
    [C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj]

Build FAILED.

似乎dotnet找不到GenerateFileFromTemplate任务.

我也看到水疗模板项目正在使用街机SDK,但我不认为我真的需要.

我怎么才能解决这个问题?我还缺什么?

编辑

当我在Visual中打开两个项目时,我看到的是:

用于我的模板项目的Nuget包:

代码语言:javascript
运行
复制
C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates> dotnet restore
  Determining projects to restore...C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj : warning NU1604: Project dependency Microsoft.DotNet.Build.Tasks.Templating does not contain an inclusive lower bound. 
  Include a lower bound in the dependency version to ensure consistent restore results.
C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj : error NU1101: Unable to find package Microsoft.DotNet.Build.Tasks.Templating. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Local, Microsoft Visual Studio Offline Packages, nuget.org
  Failed to restore C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj (in 516 ms).

水疗套餐-模板:

代码语言:javascript
运行
复制
C:\repos\spa-templates\src> dotnet restore
  Determining projects to restore...
C:\repos\spa-templates\src\Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj : warning NU1603: Microsoft.DotNet.Web.Spa.ProjectTemplates.7.0 depends on Microsoft.DotNet.Build.Tasks.Templating (>= 6.0.0-beta.21373.11) but Microsoft.DotNet.Build.Tasks.Templating 6.0.0-beta.21373.11 was not found. An approximate best match of Microsoft.DotNet.Build.Tasks.Templating 6.0.0-beta.22212.5 was resolved.
  All projects are up-to-date for restore.

因此,dotnet还原似乎无法恢复此包。但是,对于两个项目,nuget源代码都是相同的:

代码语言:javascript
运行
复制
IdentityServer.Templates>dotnet nuget list source
Registered Sources:
  1.  nuget.org [Enabled]
      https://api.nuget.org/v3/index.json
  2.  Local [Enabled]
      C:\packages
  3.  Microsoft Visual Studio Offline Packages [Enabled]
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\



C:\repos\spa-templates>dotnet nuget list source
Registered Sources:
  1.  nuget.org [Enabled]
      https://api.nuget.org/v3/index.json
  2.  Local [Enabled]
      C:\packages
  3.  Microsoft Visual Studio Offline Packages [Enabled]
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

编辑2

嗯,看来GenerateFileFromTemplate是Arcade的一部分.(何图)

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73334155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档