I'm trying to add the .nuget directory as a package source, because we dont have a remote feed and we just had the need for one. I'm modifying the Nuget.targets file like this:
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!-- -->
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="../.nuget" />
</ItemGroup>
However I get a message when building the project that says "Invalid URI cannot determine the format".
Is there a way to add a local folder for packages restore?
NuGet must be using the Uri class to get the path. Try the following instead:
<PackageSource Include="$(SolutionDir).nuget"/>
$(SolutionDir) will expand to the full path of the solution directory followed by a forward slash and this seems to work with package restore.
Related
I have a project which is referring packages from nuget. These packages from nuget have their XML documentation file included as part of the package (present in .nupkg file at /lib/netstandard2.0/<projectName>.xml along with <projectName>.dll file)
The XML documentation file is getting generated by adding below in csproj file:
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Now when I am publishing the project which has these nuget packages references, the xml documenation file of the referred nuget packages is not becoming part of publish.
It seems this is an ongoing issue.
Is there a workaround to include xml documentation of referred packages ?
Found a solution which is making this work. Added below in the `.csproj' file:
<Target Name="_ResolvePublishNuGetPackagePdbsAndXml"
AfterTargets="RunResolvePublishAssemblies">
<ItemGroup>
<ResolvedFileToPublish
Include="#(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).pdb')"
RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))"
DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))"
Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''
and Exists('%(RootDir)%(Directory)%(Filename).pdb')" />
<ResolvedFileToPublish
Include="#(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).xml')"
RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))"
DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))"
Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''
and Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target>
It will make xml (and pdb if present) files of referred packages become part of published files.
The past couple of days I've been getting warnings when compiling my .NET Standard/Core projects:
NuGet.Build.Tasks.Pack.targets(202, 5): [NU5125] The 'licenseUrl' element will be deprecated. Consider using the 'license' element instead.
To fix this, I switched to using <PackageLicenseFile>...</PackageLicenseFile> instead of <PackageLicenseUrl>...</PackageLicenseUrl>.
However, in order for this to work, I have to add the license file to my package (naturally), but it gets added to the content and contentFiles directory, which means that a project using this package gets the license file added to it.
Is there a way to embed the license file so that PackageLicenseFile works correctly, without adding the license file to projects using the package?
This is the section I added to the .csproj file in order to embed the license file:
<ItemGroup>
<Content Include="..\LICENSE" />
</ItemGroup>
The output package structure:
_rels
package
lib
contentFiles
+- any
+- netstandard2.0
+- LICENSE
content
+- LICENSE
Could I, for instance, add it to a separate folder inside the package, other than content?
The recommended way of packing a licence file with the package is
<PropertyGroup>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<None Include="LICENSE.txt" Pack="true" PackagePath="$(PackageLicenseFile)"/>
</ItemGroup>
But also there now is PackageLicenseExpression which can be used as an alternative to license files / URLs as you have mentioned in your comment.
See NuGet's wiki entry Packaging License within the nupkg for more details.
I'm developing a .NET Core 2.1 library that depends on an unmanaged DLL. I'd like to include the unmanaged DLL in the NuGet package as well. The problem that I am running into is that if I try to specify all of the information in the .csproj file, the dotnet build process throws the following warning:
warning NU5100: The assembly 'content\lib\subdir\somedll.dll' is not
inside the 'lib' folder and hence it won't be added as a reference
when the package is installed into a project. Move it into the
'lib' folder if it needs to be referenced.
I know that I can embed the unmanaged DLLs by writing a .nuspec (in fact, I have). However, it seems like I shouldn't need to write one with the latest .csproj file format.
Question: How can I use the .csproj file to embed unmanaged DLLs in a NuGet package?
Specifying <ItemGroup><None> in the .csproj file seems to include the files in the output directory but they do not make it into the NuGet package.
Specifying <ItemGroup><Content> in t he .csproj file will get them added to the NuGet package but in the Content directory instead of in the Lib directory.
If I really have to have both a .csproj file and a .nuspec file, what is the best practice for where to put the metadata? In t he .csproj file? In the .nuspec file? Maintain and sync both? Is there a something in the tool chain that can do this for me?
I'm working in Visual Studio Code V1.24, and .NET Core/dotnet V2.1.
You need to specify explicit package path metadata on the element so that the dll/so/dylib file ends up at the right place in the package so that it is recognised as runtime-specific native DLL:
<ItemGroup>
<None Include="unmanaged.dll" Pack="true" PackagePath="runtimes\win-x64\native" />
</ItemGroup>
I'm working on installation package of an application with a few additional ones, required for it to work. Here's a structure I have so far:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Bundle ...>
<BootstrapperApplicationRef ... />
<Chain>
<MsiPackage ... />
<ExePackage ... />
<MsiPackage ... />
</Chain>
</Bundle>
I need to create a few directories for one of the applications (these directories won't be used upon installation). But I have no idea how to accomplish this.
I've found a lot of examples of creating directories under <Product> section. But when I use <Directory> tag inside <Bundle>, it says, that: "The Bundle element contains an unexpected child element 'Directory'".
I'm new to this tool and might be missing some basic concept. Can anyone help me understand where am I wrong?
Bundles install packages and packages are what update the machine. So to create directories, do so in the application package.
I was created one nuget package using following step.
First I created one Asp.net Mvc application
The I created spec file using nuget spec command
Then I edited $id$,$version$,$author$,$description$ ect..
Then I created package using following command.
nuget pack myproject.csproj -Build -Properties Configuration=Release
It was created one myproject.1.0.0.0.nupkg
Then I copy the file And past into C:\LocalNuGetFeed\myproject.1.0.0.0.nupkg
I already configure the local repository in my VS
My problem is
When I install this package from any other project it ask following question.
But as per my requirement I don't want to move this file to target project. Suppose user give y the it overwrite the target project file because of it i face lot reference problem.
**File Conflict
File 'Web.config' already exists in project 'CRM'. Do you want to overwrite it?
[Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "N"):
File Conflict
File 'Global.asax' already exists in project 'CRM'. Do you want to overwrite it?
[Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "N"):**
But in my package I don't want to move this above two file from package to target project.
Is any way to avoid transform Global.asax and Web.config move from package to target project.
In my .nuspec file I added following line
<files>
<file src="Web.config" target = "" exclude="Web.config"/>
<file src="*.asax" target = "" exclude="*.asax"/>
<file src="Content\*.css" target="Content\" />
<file src="Scripts\*.js" target="Content\Scripts\" />
</files>
But it include the web.config file AND Global.aspx file in Content folder My resultant package look like bellow
myproject.1.0.0.0
>> Content
....css
>>Script
..Js file
web.config
Global.asax
I was solved this using following command to crate package
nuget pack CrmHtmlController.csproj -IncludeReferencedProjects -Exclude **\*.config;**\*.asax
so it exclude all .congig and .asax file from package.
Take a look at your .nuspec file. It's just an XML file, so you can open it up with any text editor. See how it define which files to include at <package><files>? Remove those files that you don't want. A handy tool if you want to do this with a GUI is NuGet Package Manager.
Nuget includes the web.config in your package, because the build action of the web.config is "Content". This is by default and necessary for a classic publish of an asp.net web site.
If you don't want this, propably because your assembly is only a component of another web site, you can change the build action to "None" and nuget will not take it any longer.