I have a problem with the WinSCP.exe file in my created NuGet package.
I reference WinSCP in my project as follows:
<PackageReference Include="WinSCP" version="5.17.10" />
After packing my NuGet package, the winscp.exe is copied to the package in contentFiles. When I reference my package in other projects/NuGet packages, the winscp.exe is also copied into the package. I don't like that, because I want to use the references and download it while package restore (obviously).
But I don't know how I can exclude the .exe from my package.
I tried this:
<PackageReference Include="WinSCP" version="5.17.10" >
<PrivateAssets>none</PrivateAssets>
<IncludeAssets>all</IncludeAssets>
<ExcludeAssets>contentFiles;build;runtime;native;analyzers</ExcludeAssets>
</PackageReference>
This works for the first/lowest package, the .exe isn't copied and the reference is set in nuspec.
But for higher packages, which reference MY package (with reference WinSCP in nuspec), the .exe file isn't restored.
One workaround is as far as I can see, that I add for each package which is using my first/lowest package, the same reference again:
<PackageReference Include="WinSCP" version="5.17.10" >
<PrivateAssets>none</PrivateAssets>
<IncludeAssets>all</IncludeAssets>
<ExcludeAssets>contentFiles;build;runtime;native;analyzers</ExcludeAssets>
</PackageReference>
But I don't think, that is the intended way..
I'm wondering if the nuget-package structure of the .nupkg is the source of the problem/behavior. The Winscp.dll is stored in lib/net40, but the Winscp.exe is in tools/ folder. Official Microsoft Documentation doesn't describe well, where .exe files should be stored and for what "tools" is for...
Thanks for any help.
Related
I have a Visual Studio project that I have made into a NuGet package. The project has a file in it (called SwaggerIndex.html). I have set that file to have the "Copy to Output Directory" property to "Copy if newer". (I need this file to copy to the build folder on build.)
In that solution it works just fine. (I created another project to test it, and when it references my project that has the SwaggerIndex.html, it outputs it to the build folder just fine.)
However, when I package it into a NuGet and pull it into another solution/project, the SwaggerIndex.html file is not output on build.
I am making my NuGet package by going to the project's "Package" properties tab and selecting "Generate NuGet package on build". All projects involved are running .Net Core 3.1.
How can I get my NuGet Package to create my SwaggerIndex.html file on build (like it does when it is just a normal project)?
Please try these:
I have two solutions for you to solve the issue.
Solution 1
If you just want to install this nuget package only in new sdk projects(Net Core and Net Standard projects), you could use this
1) add these node in your xxx.csproj file:
<ItemGroup>
<None Include="xxx\SwaggerIndex.html(the path of SwaggerIndex.html file in your project)" Pack="true" PackagePath="contentFiles\any\any">
<PackageCopyToOutput>true</PackageCopyToOutput>
</None>
</ItemGroup>
2) then repack your nuget project, and before you install the new version, you should first clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages
Solution 2
If you want this nuget package to copy SwaggerIndex.html file in both Net Framework and Net Core projects, you should use this:
1) add a file called <package_id>.props file in your nuget project. You should note that if your nuget package named as SwaggerIndex.1.0.0.nupkg, you should name the file as SwaggerIndex.props file so that it will work.
In my side, I put it into a folder called build.
2) then add these content in SwaggerIndex.props file,
<Project>
<Target Name="CopyToOutputFolder" BeforeTargets="Build">
<ItemGroup>
<File Include="$(MSBuildThisFileDirectory)..\File\*.*"></File>
</ItemGroup>
<Copy SourceFiles="#(File)" DestinationFolder="$(TargetDir)"></Copy>
</Target>
</Project>
3) add these in xxx.csproj file of your nuget project.
<ItemGroup>
<None Include="SwaggerIndex.html" Pack="true" PackagePath="File"></None>
<None Include="build\SwaggerIndex.props" Pack="true" PackagePath="build"></None>
</ItemGroup>
4) then repack your nuget package, before installing this new version of the nuget package, you should first clean all nuget caches first.
When you finishing installing the new version of the nuget package, click Build and the file will be copied into the main project.
Besides, there is also a similar issue about this.
We are trying to control versions of nugets being used by hosting them on our own Artifactory and not on nuget.org while trying to package multiple nugets into one.
Example for this is Aspose.
I want to create a new library called AsposeTools that has our own helper functions.
AsposeTools references: Aspose.Cells and Aspose.PDF.
When I install AsposeTools in my project, I want to see AsposeTools, Aspose.Cells and Aspose.PDF so that I can call to use both my helper functions and the actual Aspose functions.
But I want Apose.Cells and Aspose.PDF to be "installed" by AsposeTools not dependencies that get copied down from our artifactory or nuget.org. The reason being cause then we need to maintain version of cells and pdf in both our artifactory and what's being used in tools.
How can I tell the dependency to install from within the nuget it exists instead of a nuget source.
I've tried creating a libs folder within AsposeTools and added the extra dlls to that folder and added them as references. I then tried all the different options for build actions with Copy to Output Directory set to always. The best I could get is that, telling by file size, AsposeTools has the extra dlls included, but I cant actually refence them in code, only my helper functions. The Aspose.Cells and Aspose.PDF are not actually placed in the projects references
EDIT: I use .csproj currently to build the nuget
If my comment's guess is right, you can just set these Apose.Cells.dll and Aspose.PDF.dll as assembly reference so that it will not install them as nuget packages from nuget.org.
Note: it will miss any dependencies of the nuget packages and if you want, you can use the same way to add them automatically.
1) click these nuget packages on the Dependencies -->Properties and then set their Private Asserts to All.
Then, right-click on the project-->Unload project and then click reload Project to enable the settings.
2) enter the xxx.csproj file of the project and then add these:
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<None Include="$(OutputPath)Aspose.Cells.dll" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
<None Include="$(OutputPath)Aspose.PDF.dll" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
// you can add any dependency dlls of the output folder in this way as you want
</ItemGroup>
3) repack your project and when you install the new version, you should first clean nuget caches or just delete caches files under C:\Users\xxx(current user)\.nuget\packages.
When you install the new AsposeTools package, it will not install the other two packages as nuget dependencies from nuget.org. And they are only referenced by the main project only as Assembly reference and also copied into output folder.
ConsoleApp2 is the new main project, and I have installed the new version of AsposeTools package into my project. And this is the effect:
I am trying to get rid of nuget packages and have only local dll files in the project.
These packages I have excluded
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
So, I've built my solution and imported all the dlls in the project. I can compile it, but the server says:
An unhandled exception occurred while processing the request. InvalidOperationException: The view 'Index' was not found. The following locations were searched: ...
But having the same with nuget makes the work fine. What is an alternative to add dlls to the project?
I've seen this, but in my case I have too many files with the same name when I put all the dlls in one folder (conflicts)
You can always add NUget source which is local folder from you drive and make it as default or the only source of dependencies.
Here are more details Local feeds
Replace asp.net core NuGet packages with local dll files. What is an
alternative to add dlls to the project?
I am trying to get rid of nuget packages and have only local dll files
in the project.
Nuget is a recommended way to manage the assemblies for your project. When you have access to Internet, using nuget is very convenient for your situation.
But according to your another post here, you're trying to develop/build the project in environment with no Internet. If so, we can still use nuget for this situation:
Step1: Clear all Nuget cache in VS=>Tools=>Options=>Nuget Package Manager=>General. (All packages you once used in VS are cached in %userprofile%\.nuget\packages, we can easy to restore the packages using nuget store, so feel free to clear the cache)
Step2: Delete the bin and obj folders of your current web project, and then restore packages for only your current project.(nuget restore, dotnet restore or simply rebuild the project in VS,VS will restore the packages for you)
Step3: Now let's navigate to the %userprofile%\.nuget\packages folder, now every packages in packages folder is that your current project depends on. Let's rename the folder name from packages to mypackages. Now all the packages(assemblies) your project need are in mypackages folder.
Step4: We can then copy/move this folder into your project folder. We can add this folder into source control or what depending on your actual needs. You can feel free to deploy your project to another server(no-internet) and continue on your work.
As to how to reference them, you can fetch the assemblies you need from mypackages folder and manually reference them.(Add=>Reference=>...). Or use this better way with nuget, add the path where your mypackages folder exist to Package Source, you can restore the packages for your project easily even in no-Internet environment.
Hope it helps and feel free to let me know if you need any further info or support :)
Probably missing a reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation. You can add a dll for this package and then compile the Project or solution.
I'm trying to setup a library nuget package for .net core with the dotnet pack command, however, instead of just having a dll included in the nuget package, a content file from another references nuget is added (which makes the nuget file size 9.6MB instead of 59KB).
Is there a way to avoid getting files and content from other nuget packages in a nuget library project?
to reproduce:
Create a .net core library
Add Hl7.Fhir.Specification.STU3 nuget reference
run dotnet pack
The nuspec file in the newly created nuget package, will reveal that the specification.zip file is regarded as content that must be added.
I've tried testing with a custom nuspec file which is basicly a copy from the dotnet output, but without the content reference. The problem I see, is that the nuspec file contains a lot of references which must be maintained somehow.
Peter Wurzinger's suggestion worked for me. It's a shame he posted as a comment, rather than an answer, since he deserves the rep points. Anyway, this is my csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hl7.Fhir.Specification.STU3" Version="0.96.0" ExcludeAssets="contentFiles" />
</ItemGroup>
</Project>
when I pack, the bin\Debug\test.1.0.0.nuspec file does not contain the specification.zip file elements that exists when I don't use ExcludeAssets.
I'd like iterate on a nuget package without continuously pushing the package to a nuget feed.
I'm wondering if it's possible to conditionally add a project reference instead of a nuget package reference via a target or props file in csproj files that would allow me to locally debug my nuget package.
In my csproj I would have:
<Reference Include="A">
if(Exists(localOverrides.props) {
<HintPath>localOverrides.A.HintPath</HintPath>
} else {
<HintPath>..\packages\A.dll</HintPath>
}
</Reference>
and localOverrides.props would be a file listed in my .gitignore that developers could add lines to like:
A -> C:\Repos\A\bin\A.dll
Am I on the wrong path? Surely there must be a more sustainable way to quickly iterate and debug a nuget package then creating pre-release packages on every change
The way I have always debugged Nuget package is once you have that package added to your solution through Nuget, you then make changes to the Nuget DLLs and just copy them into the correct folder in the packages folder for the project consuming the Nuget package.
All you have to do is compile the solution that Nuget project solution in debug mode and just copy/paste them into the consuming project's packages folder. You could make this even simpler by writing a batch script and adding it as a post build event to the Nuget project that just copied the DLLs into the correct folder for you.
There is a much easier way, in which you could use both: project references during development (faster), and package references during production.
In your .csproj project file:
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<ProjectReference Include="../../../Library1/Library1.csproj" />
<ProjectReference Include="../../../Library2/Library2.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'!='Debug'">
<PackageReference Include="Library1" Version="1.0.0" />
<PackageReference Include="Library2" Version="1.0.0" />
</ItemGroup>
In development: project compiled in debug mode, so the project reference will be used.
In production (CI server, docker container): project compiled in release mode, so the package reference will be used.
If all you want to acomplish is to debug the NuGet package I suggest you use "dotpeek debug server" option. This way you don't need to do anything with the reference and simply debug the package or whatever you want.
https://confluence.jetbrains.com/plugins/servlet/mobile#content/view/53336814
Sounds like you want a test project (unit or integration) in the same solution as your NuGet packaged assembly project. Then you can prove it's correctness independently of any consumers of the NuGet package. Good tests will also help ensure you don't break anything unintentionally when updating the package in the future.