为什么nuget包中包含的静态资源在project.assets.json文件中,但实际上不在项目中

问题描述 投票:0回答:1

我在我想要打包的

Client1.csproj
中使用此代码:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> 
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>    
    <ImplicitUsings>enable</ImplicitUsings>
    <AssemblyVersion>1.0.0.8794</AssemblyVersion>    
    <StaticWebAssetBasePath>Client1</StaticWebAssetBasePath>   
    <IsPackable>true</IsPackable>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <NoBuild>true</NoBuild>
    <IncludeBuildOutput>false</IncludeBuildOutput>
    <NuspecFile>$(SolutionDir)\Client1\Client1.nuspec</NuspecFile>   
  </PropertyGroup>

这是我的

nuspec
文件:

<?xml version="1.0"?>
<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>Client1</id>
    <version>1.2.53</version>    
    <title>Client1</title>
    <description>Desc</description>
    <authors>mz</authors>
    <owners>me</owners>    
    <requireLicenseAcceptance>false</requireLicenseAcceptance>    
    <releaseNotes>notes</releaseNotes>
    <copyright></copyright>
    <tags></tags>
    <dependencies>
      <dependency id="Microsoft.AspNetCore.Components.Web" version="8.0.0" />
      <dependency id="NuGet.Build.Tasks.Pack" version="6.8.0" />
      <dependency id="Microsoft.AspNetCore.Components.WebAssembly" version="8.0.0" />
      <dependency id="Microsoft.AspNetCore.Components.WebAssembly.DevServer" version="8.0.0" />
      <dependency id="MudBlazor" version="6.12.0" />    
    </dependencies>
    <summary></summary>
    <contentFiles>      
      <files include="wwwroot/css/*.css" buildAction="Content" copyToOutput="true" flatten="true" />
    </contentFiles>
  </metadata>
  <files>    
    <file src="wwwroot\css\*.css" target="content\css" />  
    <file src="bin\Release\net8.0\Client1.dll" target="lib\net8.0" />            
  </files>
</package>

这是我在目标项目上安装软件包时

project.assets.json
文件的一部分:

"libraries": {
  "Client1/1.2.53": {
    "sha512": "kYwkGQ4Ea5/UXFy8yi15FanZ5dv1n5FV8mj7SXxo5fID+0VAoHLMQ1ig+ePOWYXWJqLCYAxylBaz9KjgPCubXw==",
    "type": "package",
    "path": "client1/1.2.53",
    "files": [
      ".nupkg.metadata",
      "client1.1.2.53.nupkg.sha512",
      "client1.nuspec",
      "content/css/app.css",
      "lib/net8.0/Client1.dll"
    ]
  },

但是有了这些,

https://localhost:nnnn/content/css/app.css
出现了404错误,如何解决这个问题?

nuget blazor-webassembly nuspec
1个回答
0
投票

它们实际上并不存在于项目目录中。相反,它们在构建过程中从 NuGet 包中提取并包含在输出目录中。

© www.soinside.com 2019 - 2024. All rights reserved.