in net48 the build included the exe output file (NOT dll) of a project into the resulting *.nupkg file.
I want that behavior for net6.0: How to Include the Project output exe-File into the nupkg (in folder \lib\net6.0)? Currently it only includes dll and config.
I tried to include the files using ItemGroup but doesn't work:
<ItemGroup>
<None Include="$(OutputPath)\$(MSBuildProjectName).exe" Pack="true" PackagePath="lib\$(TargetFramework)">
<PackageCopyToOutput>true</PackageCopyToOutput>
<Visible>false</Visible>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
But it doesn't correctly resolve the paths - its missing the Target Framework (net6.0) part.
If i write $(OutputPath) it should contain the net6.0 automatically, but it does not.
If i insert "net6.0" manually ... it ... appears... twice? ("...\net6.0\net6.0\...")
How to include project output exe files of the output directory into nupkg ?
Thank you very much.
Related
Here's my code:
<ItemGroup>
<Content Include="$(ProjectDir)..\Translations\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Basically I tell the project to go on folder up, and copy EVERYTHIN inside Translations folder to the output directory.
However, when I go to the output, I see that there is not Translations directory. Only its files are copied directly inside the bin folder.
What I want is to preserve that Translations folder too. In other words, the files should be copied to bin\Translations directory.
What should I do to get that result?
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.
If a library (eg, on github) doesn't distribute itself via a nuget package, I'd have to manually include it as a reference, correct? I see a lot of reference posts for how to add a reference to a project for Visual Studio, but I can't seem to figure out how to do it on Visual Studio Code.
In this case, I've downloaded the library's zip, and moved the expanded folder into my project, and then tried using <namespace>, which did not work.
EDIT:
I noticed that this downloaded zip contained a .nuspec. Is there something I can do with this file extension to import it in my project?
Let's say you have two projects:
1) Project1.Api
2) Project2.Executable
Command line syntax for dotnet add reference:
cd Project2.Executable
dotnet add reference ../Project1.Api/Project1.Api.csproj
If you check the Project2.Executable.csproj file, you will see the following entry:
<ItemGroup>
<ProjectReference Include = "..\Project1.Api\Project1.Api.csproj" />
</ItemGroup>
Add "vscode-solution-explorer" Extension. It will folder structure as visual studio.
Right click on project --> Add Reference --> Select the reference project from the list.
You can open .csproj file of the project you want to add reference to and add project reference like this:
<ItemGroup>
<ProjectReference Include = "<RELATIVE_PATH_TO_REFERENCE_PROJECT>" />
</ItemGroup>
If the ItemGroup for ProjectReference already exist then you can just add to it.
Example:
<ItemGroup>
<ProjectReference Include = "../MyLibrary.csproj" />
</ItemGroup>
In visual studio, in the solution explorer, expand the project that will reference this other library. You will see "References", right click and choose "Add". Then choose browse on the left. Find your dll in your file system. If vs can't find the library you may need to unzip it. I've read where you may need to copy the dll into the bin folders, I recommend trying it without doing that, then copying it in to them if it fails without them.
Btw Googling "visual studio add reference" comes up with A LOT of great results.
I have a web project that has a post-build event that produces some minified files. Assume for the moment that this needs to remain a post- build event, and cannot be changed into a pre-build event.
I have successfully used a .wpp.targets file to package additional files:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<SourceRoot>$(BuildDirectory)\Sources\Web</SourceRoot>
</PropertyGroup>
<ItemGroup>
<FilesForPackagingFromProject Include="$(SourceRoot)\ExtraScripts\Normal.js">
<DestinationRelativePath>Scripts\%(RecursiveDir)%(FileName)%(Extension)</DestinationRelativePath>
<FromTarget>Web.wpp.targets</FromTarget>
</FilesForPackagingFromProject>
</ItemGroup>
</Project>
Unfortunately, this fails when I do the same thing for the files produced by the post-build step. This is because the CopyAllFilesToSingleFolderForMsdeploy target executes before the build. Even before the PrepareForBuild target.
Is there a way to add extra files and folders to the deploy package when they are produced during the build?
There was a similar question before (Add Plugin DLL in MVC 4 Website after publish).
You can deploy files only if they have been a part of your project before.
What we usually do is that we include those files as dummy files in our project and overwrite them during the build process. Because those files are part of your project, this approach will publish those files.
I have a web application project that references a third party assembly, which in turn uses some native dlls that it needs to find at runtime.
Because of that, I wanted to add these dlls to the bin folder of the project, so that they can definitely be found.
However, if I add the files to the project in /bin/, select "copy to output", the files are compiled and published into /bin/bin. Adding them to the root folder works, but can hardly be the right solution.
Adding them to the build target "AfterBuild" has no effect when publishing (e.g. "build deployment package")
It also has to work when building the solution via TFS, where the MSBuild target _CopyWebApplicationLegacy is invoked.
The solution was a combination of the things I had tried already:
Include the "Bin" folder in the project
Add the needed files (I added them as a link due to our development structure)
Set the following properties: "Build Action = Content" and "Copy to Output = Do Not Copy"
The files are now copied to the bin folder when publishing, even when automating the builds on TFS.
The component that needed this was GdPicture, which uses a couple of native DLLs during runtime.
It's common to have a lib folder in either your solution or workspace to put your third party dlls within. You would then add a reference to this location from your project and ensure this location is under source control.
You could also look at using NuGet to package this for you, which uses a solution level packages folder automatically.
Based on this article http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx. It's possible to define the msbuild target into main (lastest in order of solution's build) project file that will capture all files of the bin folder. Like this
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="$(OutDir)\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>$(OutDir)\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
And place it before closing root project element.