I'm using the following *.targets file to add build actions
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\libeay32.dll">
<Link>libeay32.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\COMAssinaDocs.dll">
<Link>COMAssinaDocs.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\InterOps.ComAssinaDocs.dll">
<Link>InterOps.ComAssinaDocs.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\ssleay32.dll">
<Link>ssleay32.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
and this is the nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>xxx.Providers.SignDocs</id>
</metadata>
<files>
<file src="bin\Release\xxx.Providers.SignDocs.targets" target="build" />
<file src="bin\Release\xxx.Providers.SignDocs.dll" target="lib\net45" />
<file src="bin\Release\xxx.Providers.SignDocs.Impl.dll" target="lib\net45" />
</files>
</package>
And I'm using this piece of nuget documentation to build this package:
Including MSBuild props and targets in a package
Basically what I want is to get a few unmanaged dlls copied to the output folder of the project using the package and even tho I am following the instructions the target project file targets setion iss not added and therefore the files are not copied to the output directory. What am I missing?
UPDATE
Was able to get it working using the configurations bellow.
xxx.Providers.SignDocs.targets
<None Include="$(MSBuildThisFileDirectory)\libeay32.dll">
<Link>libeay32.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\COMAssinaDocs.dll">
<Link>COMAssinaDocs.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\InterOps.ComAssinaDocs.dll">
<Link>InterOps.ComAssinaDocs.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)\ssleay32.dll">
<Link>ssleay32.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>xxx.Providers.SignDocs</id>
</metadata>
<files>
<file src="..\..\tools\libeay32.dll" target="build" />
<file src="..\..\tools\COMAssinaDocs.dll" target="build" />
<file src="..\..\tools\InterOps.ComAssinaDocs.dll" target="build" />
<file src="..\..\tools\ssleay32.dll" target="build" />
<file src="bin\Release\xxx.Providers.SignDocs.targets" target="build" />
<file src="bin\Release\xxx.Providers.SignDocs.dll" target="lib\net45" />
<file src="bin\Release\xxx.Providers.SignDocs.Impl.dll" target="lib\net45" />
</files>
</package>
The targets file needs to be included in the 'package/files' element of the nuspec file, otherwise it isn't included in the package. It needs a target of 'build'.
The targets file also needs to be named the same as the package.
Related
Adding a binary file to the "contentFiles" of my nuget package leads to a build error in my C# project.
CSC : error CS2015: '...\0.0.14\contentFiles\any\any\archive.7z' is a binary file instead of a text file [...]
My goal is to have this binary file in my build output folder after dotnet build and dotnet publish.
details:
# .nuspec
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
<contentFiles>
<files include="archive.7z" flatten="true" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="content/archive.7z" target="contentFiles\any\any" />
</files>
</package>
# folder structure
├───content
│ └───archive.7z
└───.nuspec
# .csproj file
<ItemGroup>
<PackageReference Include="my-nuget-package-name" Version="0.0.14" />
</ItemGroup>
Be sure to add the path to contentFiles "any/any/archive.7z"
<files include="any/any/archive.7z" flatten="true" buildAction="None" copyToOutput="true" />
so the correct .nuspec file should look like this:
# .nuspec
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
<contentFiles>
<files include="any/any/archive.7z" flatten="true" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="content/archive.7z" target="contentFiles\any\any" />
</files>
</package>
When I publish our blazor server app via Visual Studio to a local folder all is fine. We get a single wwwroot folder with all the css etc in it. However when deployed via Blazor to the server we get the wwwroot folder inside another wwwroot folder for some reason. Does anyone know what could be the issue?
I found the problem and it was a little curious.
Basically I had the following in the csproj file for the client project.
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Content Remove="wwwroot\css\bootstrap-select.css" />
<Content Remove="wwwroot\css\bootstrap-select.min.css" />
<Content Remove="wwwroot\css\bootstrap-theme.css" />
<Content Remove="wwwroot\css\bootstrap-theme.min.css" />
<Content Remove="wwwroot\css\bootstrap.css" />
<Content Remove="wwwroot\css\bootstrap.min.css" />
<Content Remove="wwwroot\css\cust-bootstrap.css" />
<Content Remove="wwwroot\css\cust.css" />
<Content Remove="wwwroot\css\navbar.css" />
<Content Remove="wwwroot\css\site.css" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\css\bootstrap-select.css" />
<None Include="wwwroot\css\bootstrap-select.min.css" />
<None Include="wwwroot\css\bootstrap-theme.css" />
<None Include="wwwroot\css\bootstrap-theme.min.css" />
<None Include="wwwroot\css\bootstrap.css" />
<None Include="wwwroot\css\bootstrap.min.css" />
<None Include="wwwroot\css\custbootstrap.css" />
<None Include="wwwroot\css\cust.css" />
<None Include="wwwroot\css\navbar.css" />
<None Include="wwwroot\css\site.css" />
<None Include="wwwroot\img\navbarlogo.png" />
<None Include="wwwroot\js\bootstrap-select.min.js" />
<None Include="wwwroot\js\bootstrap.js" />
<None Include="wwwroot\js\bootstrap.min.js" />
<None Include="wwwroot\js\references.js" />
<None Include="wwwroot\js\site.js" />
<None Include="wwwroot\static\master.html" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
<PackageReference Include="PSC.Blazor.Components.Tabs" Version="1.0.6" />
I Noticed that one of my other Blazor projects did not have these in. I removed the wwwroot entries from this file and it fixed the double folder issue.
I have no idea how they got into the project file in the first place...
I'm able to add a dll and make sure it's in lib and ref folders so I can avoid the MSB3246, NU5128, and NU5131 warnings in a .nuspec file.
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>NewDll</id>
<version>1.0.0</version>
<title>NewDll</title>
<authors>Dll Dev Team</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>https://new.dll.com</projectUrl>
<description>Allow NewDll dll to be used in .NET Framework 4.8 as a nuget package.</description>
<releaseNotes>Remove missing reference assembly warning.</releaseNotes>
<copyright>2021</copyright>
<dependencies>
<group targetFramework=".NETFramework4.8">
</group>
</dependencies>
<references>
<group targetFramework="net48">
<reference file="newdll.dll" />
</group>
</references>
</metadata>
<files>
<file src="C:\Users\me\source\repos\Project1\dlls\newdll.dll" target="lib\net48\newdll.dll" />
<file src="C:\Users\me\source\repos\Project1\dlls\newdll.dll" target="ref\net48\newdll.dll" />
</files>
</package>
But I don't know how to do that in a .csproj file. I've gotten only part of the way there.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<Description>Put NewDll.dll to be used in .NET Framework 4.8 as a nuget package.</Description>
<PackageReleaseNotes>Remove missing reference assembly warning.</PackageReleaseNotes>
<Version>1.0.0</Version>
</PropertyGroup>
<!-- How do I add a reference? -->
<ItemGroup>
<Content Include="NewDll.dll">
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
</ItemGroup>
</Project>
How do I make sure that the dll also creates the ref folder in the nuget package in the .csproj?
You can add multiple paths to PackagePath, e.g.:
<ItemGroup>
<None Include="NewDll.dll">
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework);ref\$(TargetFramework)</PackagePath>
</None>
</ItemGroup>
I have a NuGet package that depends on another NuGet package but I want to replace one of the unmanaged DLLs with one of mine. This works well, but now I'm trying to add support for both x86 and x64 using a .targets file. When my target application builds, it pulls down the original version, not the replacement.
Here's my .nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>MyPackage</id>
<version>2.0.0</version>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<dependency id="YourPackage" version="1.0.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="MyPackage.targets" target="build\net452" />
<file src="..\lib\x86\thepackage.dll" target="lib\net452\x86" />
<file src="..\lib\x64\thepackage.dll" target="lib\net452\x64" />
</files>
</package>
Here's my .targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
Condition="(('$(Platform)' != 'x86') AND ('$(Platform)' != 'x64'))">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)' platform. You need to specify platform (x86 or x64)." />
</Target>
<Target Name="InjectReference" AfterTargets="ResolveAssemblyReferences">
<ItemGroup Condition="'$(Platform)' == 'x86' or '$(Platform)' == 'x64'">
<Reference Include="MyPackage">
<HintPath>$(MSBuildThisFileDirectory)$(Platform)\thepackage.dll</HintPath>
</Reference>
</ItemGroup>
</Target>
</Project>
What am I doing wrong?
EDIT: If I change the .nuspec...
<file src="..\lib\x86\thepackage.dll" target="lib\net452" />
<file src="..\lib\x64\thepackage.dll" target="lib\net452" />
... then it pulls down my version but uses x86 for both x86 and x64 builds.
I solved it by putting the files in the build folder and then simply copying the target file.
.nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>MyPackage</id>
<version>2.0.0</version>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<dependency id="YourPackage" version="1.0.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="MyPackage.targets" target="build\net452" />
<file src="..\lib\x86\thepackage.dll" target="build\net452\x86" />
<file src="..\lib\x64\thepackage.dll" target="build\net452\x64" />
</files>
</package>
.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
Condition="(('$(Platform)' != 'x86') AND ('$(Platform)' != 'x64'))">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)' platform. You need to specify platform (x86 or x64)." />
</Target>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)$(Platform)\thepackage.dll">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
I am having a problem including a file i need in order for the project to work, here is the nuspec file that i have:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>package_name</id>
<version>1.0.1</version>
<title>x Wrapper</title>
<authors>me</authors>
<owners>me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>package desc.</description>
<releaseNotes>Bugfix to exe not being copied.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags></tags>
<dependencies>
<dependency id="x.Common.Interfaces" version="1.0.0" />
<dependency id="x.Common.Logging" version="1.0.0" />
<dependency id="x.Wrapper.Common" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="build\package_name.props" target="build\package_name.props" />
<file src="build\package_name.targets" target="build\package_name.targets" />
<file src="x.Wrapper\x.exe" target="content\x.exe" />
<file src="bin\Debug\package_name.dll" target="lib\net45\package_name.dll" />
</files>
</package>
When package is pushed and installed to nuget server there is only project dll + dependencies dll's but no other files are being copied into the project. Anyone with some more experience with nuget packages has idea on what could be going on ?