I'm using TFS2012 to publish a nuget package of a C# Visual Studio 2012 project. In this solution are many projects which I can successfully publish to the specific repository. For one project, which I added yesterday, the publisher creates the *.nupkg file as usual, but also creates a *.symbols.nupkg as well.
I cannot figure out, which setting in the project may cause this issue.
*.nuspec-file of the project:
<?xml version="1.0"?>
<package>
<metadata>
<id>xxx.xxx.xxx</id>
<version>0.1.1</version>
<title></title>
<authors>xxx</authors>
<owners>xxx</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
<releaseNotes>
- first release
</releaseNotes>
<copyright>Copyright 2016</copyright>
</metadata>
<files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net40\" />
</files>
</package>
The result in the repository looks like this:
File 1: xxx.xxx.xxx.0.1.1.nupkg
File 2: xxx.xxx.xxx.0.1.1.symbols.nupkg
But it should look like this:
File 1: xxx.xxx.xxx.0.1.1.nupkg
EDIT 1:
I use the external Tools of Visual Studio 2012 to publish to the repository:
Command: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
Arguments: $(ProjectDir)$(ProjectFileName) /t:Publish /p:xxxPackageSource=\\tfs2012\Repository
EDIT 2:
Furthemore I tried to build the package locally and published it to a local directory. Same result
Related
Im using Visual Studio 2022 and created a Nuget Package using this article
https://arsenshnurkov.github.io/gentoo-mono-handbook/building-nupkg.htm
I run nuget pack and i see the nupg file and upload it to our Azure Artifacts. Below is the spec file
<package >
<metadata>
<id>myProject.csproj</id>
<version>1.0.0</version>
<authors>user</authors>
<owners>user</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Test package 1</description>
<releaseNotes>Summary of changes.</releaseNotes>
<copyright>Copyright 2023</copyright>
<tags>Tag test</tags>
</metadata>
</package>
I noticed when i install this pack into a test application it includes some dlls that are not required for the end project to run.
After some research there are suggestions to change the .csproj to exclude it from Nuget when packing following this article https://www.jocheojeda.com/2019/07/22/how-to-exclude-package-dependencies-in-a-nuget-package/
but he writes the exact question i have in mind but no example of how to do this. In the article he quotes
the answer depend on how now you create your NuGet package, in this case, I’m going to focus my answer on excluding the dependency in a package created by the info in the csproj file (there is a different approach if you use the nuspec file).
I dont want to amend the csproj file but just the nuspec file. How could i leave out files that i dont want to have bundled with my package by amending the nuspec file?
In order to include/exclude files from nuget packaging, you can add the section to nuspec config file as described here.
Following your example, the files would exclude log files from your package. Using wildcards, you can exclude any other file/dll:
<package>
<metadata>
<id>myProject.csproj</id>
<version>1.0.0</version>
<authors>user</authors>
<owners>user</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Test package 1</description>
<releaseNotes>Summary of changes.</releaseNotes>
<copyright>Copyright 2023</copyright>
<tags>Tag test</tags>
</metadata>
<files>
<file src="*.*" exclude="*.log" />
</files>
</package>
I want to create a C# app that does things with the powershell. I found many solutions on the internet how to do that like this. The most answeres to this use the Powershell class from 'Microsoft.WSMan.Runtime'. Now when I search this package in nuget and install it, it doesnt show up in the references list in visual studio and also the using statement or the 'quick fix' on a PowerShell object doesnt find it.
Did I install something wrong or do I need something else too?
Edit for more infos:
.net Version 4.6.1
Tried 'Microsoft.WSMan.Runtime'v 7.0.0 and 7.0.3
'Microsoft.WSMan.Runtime' is downloaded and avaible at './packages/Microsoft.WSMan.Runtime.7.0.0'
'packages.config' does contain the entry for 'Microsoft.WSMan.Runtime'.
I found the assembly within the package targets .net core 3.1 instead of .net framework 4.6.1. So you can't see the reference in solution explorer.
It's by design of the package author, you can download the package manually, rename the name from xx.nupkg to xx.zip to check the content of the package.
The structure of the package:
And the content of the Microsoft.WSMan.Runtime.nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
...
<dependencies>
<group targetFramework=".NETCoreApp3.1" />
</dependencies>
<contentFiles>
<files include="**/*" buildAction="None" copyToOutput="true" flatten="false" />
</contentFiles>
</metadata>
</package>
We are currently refactoring an old win forms app which uses a framework as referenced project across the whole application. I am fairly new to nuget and .net so I hope you don't mind my newbiew question.
We created a nuget package from the csproj (Syncing.nupgk). That package references other packages like Newtonsoft or Consul. When I build the project, my syncing.dll gets copied to the bin folder of the win forms project, but other dlls (newtonsoft.dll, consul.dll) are copied outside in a packages folder with a structure lib\net45 etc.
How I can tell visual studio that I also need the newtonsoft.dll in the bin folder of the project as it is a dependencie of my syncing.dll
thx!
I usually use nuspec file for this purpose. In your case, you would have Syncing.csproj.nuspec which looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Syncing</id>
<authors></authors>
<owners></owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl></licenseUrl>
<projectUrl></projectUrl>
<iconUrl></iconUrl>
<description></description>
<language></language>
<tags></tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
...
</group>
</dependencies>
</metadata>
</package>
You can look at these two links for more info:
- https://learn.microsoft.com/en-us/nuget/reference/nuspec
- This is how I'm using .nuspec file to publish the instrumentation library on https://github.com/borkke/opentracing-csharp-mongo/blob/master/src/OpenTracing.Contrib.Mongo/OpenTracing.Contrib.Mongo.csproj.nuspecnuget
I want to create a nuget package of my .net core class library.
I copied the nuget.exe file to the root folder of my Solution
Run nuget spec and Solution.nuspec file created. I modified it as below:
<?xml version="1.0"?>
<package >
<metadata>
<id>Solution</id>
<version>1.0.0</version>
<authors>cc Team</authors>
<owners>cc</owners>
<licenseUrl></licenseUrl>
<projectUrl></projectUrl>
<iconUrl></iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>c# .net</tags>
<dependencies>
<dependency id="NETStandard.Library" version="1.6.1" />
</dependencies>
<references>
<reference file="Solution.dll" />
</references>
</metadata>
<files>
<file src="Solution.dll" target="lib\netstandard1.6\Solution.dll"/>
file's node src value outpupath of my solution. (bin\Release\netstandard1.6\Solution.dll)
Run nuget pack Solution.nuspec and Solution.nupkg file created.
I put it to my package source.
Create a new .net core class library and select my Solution nuget package from local package source. It added to my project. There is no error or warning. But When I try to access a class from my Solution nuget package, it couldn't be found.I dowloaded 'Nuget Package Explorer' and opened my Solution.nupkg. Icould see Solution.dll and Solution.pdb file under lib --> netstandart1.6.
Then I searched about the error and found this :
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
After compile my Solution project it creates Solution.1.0.0-0.nupkg file and Solution.1.0.0-0.symbols. I put it to my local package source but these packages are not listed in the 'Nuget Package Manager'.
Do you have any idea?
My experience is creating package from solution sometimes crappy. Creating the package from the project file could solve the problem.
After I clean 'C:\Users\XXX.nuget\packages\Solution' folder and add package again fix my problem.
Because there is bad formatted nutget package which I tried before.
I have a custom made command line tool, which performs some code generation operations. Basically, it takes one assembly as input and, through reflection, searches for certaing custom attributes, used to trigger generation of external (JavaScript) files.
Everything works (almost) fine, but the distribution and execution of the tool is somewhat disorganized. I would like to pack it as a Nuget package (hosted in a private repository), which would essentially contain the tool and a build target that should trigger the execution of the tool.
How should I package the tool? I read about the special Nuget tool, content, and build folders, and I don't know where to put what, and how to setup a custom target.
I don't know if the question is "too broad", but even if I know pretty exactly what I need, I'm in kind of a blank page syndrome.
I would put the tool into the build directory inside the NuGet package and then have a custom MSBuild .targets file in the same build directory. This MSBuild .targets file would then be written in such a way so it is called at some point during the build process.
\build
\MyPackage.targets
Then your build targets file would insert itself into the build process:
<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
MyCustomTarget
</BuildDependsOn>
</PropertyGroup>
<Target Name=“MyCustomTarget“>
<!-- Execute tool -->
</Target>
The above should run the MyCustomTarget as the last item during the build.
In post build action specify $(SolutionDir).nuget\nuget.exe pack $(ProjectPath) -IncludeReferencedProjects.
Also you can specify nuspec file. As described here https://docs.nuget.org/create/nuspec-reference.
Example:
<?xml version="1.0"?>
<package >
<metadata>
<id>SDK</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>SDK</tags>
</metadata>
<files>
<file src="tools\install.ps1" target="tools\install.ps1" />
</files>
</package>