I created a Nuget package from my webassembly projct that works good when installed but for its content files this is the .nuspec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Client1Package</id>
<version>1.2.16</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="None" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="bin\Release\net8.0\Client1.dll" target="lib\net8.0" />
<file src="wwwroot\css\*.css" target="content\css" /> <!-- this also is not working in the main project <link href="content/css/app.css" rel="stylesheet" /> -->
</files>
</package>
I need app.css in wwwroot\css and I included all css files in this folder, But after creating the package and adding it to the main webassembly project It returns error 404 for this: <link href="contentFiles/cs/net8.0/css/app.css" rel="stylesheet" />
so is the nuspec file correct? and how to correct this?
I need app.css in wwwroot\css and I included all css files in this folder, But after creating the package and adding it to the main webassembly project It returns error 404 for this: so is the nuspec file correct? and how to correct this?
Well, according to your scenario and description, It appears that you're facing issues with the generated content files path in your NuGet package because the path contentFiles/cs/net8.0/css/app.css
is not matching your expected structure in the wwwroot/css directory
.
In order to fix, you should adjust the target attribute in your .nuspec file
to correctly reflect the desired structure.
Let' have a look in practive how we could achieve that. You can modify your code as following:
<files>
<file src="bin\Release\net8.0\Client1.dll" target="lib\net8.0" />
<file src="wwwroot\css\*.css" target="contentFiles/cs/net8.0/wwwroot/css" />
</files>
Because, content files are included in a package using the element, specifying the content folder in the target attribute. However, such files are ignored when the package is installed in a project using PackageReference, which instead uses the element. Therefore, the target should include the path relative to the root of the project.
After, above modification rebuild your nugetpackage and try to clear nuget cache.
Note: Keep in mind, the target attribute specifies the path inside the consuming project where the files will be placed. It's not the same as the path within the NuGet package itself. The target path is relative to the root of the consuming project. I would highly recommened you to check this official document for reference.