I have a following pipeline on Azure DevOps
everything works as expected however I am very confused of how to include the bower_components folder in my build package as MsBuild is not aware of the bower folder.
I am successfully able to pull down the packages to the bower_components folder however I am not aware of recommended way of how to include the folder in my final package.
Solved by adding this to my .csproj file:
<Target Name="AddBowerComponents" BeforeTargets="CopyAllFilesToSingleFolderForPackage;CopyAllFilesToSingleFolderForMsdeploy">
<Message Text="Adding bower components" Importance="high"/>
<ItemGroup>
<CustomFilesToInclude Include=".\bower_components\**\*.*" />
<FilesForPackagingFromProject Include="%(CustomFilesToInclude.Identity)">
<DestinationRelativePath>.\bower_components\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
Related
I have a dependency on the NuGet library:
<ItemGroup>
<PackageReference Include="OpenCvSharp4.Windows" Version="4.5.3.20210817" />
</ItemGroup>
This package adds the file opencv_videoio_ffmpeg453_64.dll to the bin folder, which makes some problems. I don't use FFmpeg and want to remove that file (OpenCV said that it is safe to remove it if you don't use FFmpeg backend).
So, I added these lines to the csproj file:
<Target Name="RemoveOpenCvFFmpeg" AfterTargets="AfterBuild">
<Delete Files="$(OutDir)opencv_videoio_ffmpeg453_64.dll" />
</Target>
It works and everything is fine. But when I pack my project as a NuGet package, the consumers of our library still get that file in their bin folder and it also makes them some issues.
Is there any way to delete this file from the local build and from our package in some way, so our consumer won't get this file either?
Or pack them so the consumer will not restore OpenCvSharp4.Windows by its own (I use msbuild /t:pack for packing)
I have a netstandard2.0 csproj (let's call it MyPackage) that is packed at build time (as specified by GeneratePackageOnBuild) into a nuget package. This nuget package has custom props and targets in the build directory (so referencing projects get these imported).
I have another project (let's call it MyConsumer) in the same solution for testing MyPackage. I want MyConsumer to have the build asset props and targets imported from MyPackage at build time, just as if it were consuming it as a PackageReference from some remote nuget source.
How can I get this working (most simply)?
I have been able to do it via a very convoluted method where I have MyConsumer add a PackageReference to MyPackage and override the RestoreSources in MyConsumer to point to the bin directory of MyPackage. This gets very weird when running dotnet build or Visual Studio build of the sln, because project metadata is generated upfront for all projects during Restore and thus MyPackage doesn't exist at that point. The resolution was to add nested calls to MSBuild within the MyConsumer project, but then this becomes even worse, since Visual Studio restores operate quite differently than that automatic restores performed by dotnet build.
Is there any simple way of doing this?
This is what I have now
<Project>
<Target Name="Build">
<Message Text="Running inner build" Importance="high" />
<!--
Need to call MSBuild twice, once to restore, then again to restore and build to get the restore of the Sdk to work
because of this bug in MSBuild: https://github.com/Microsoft/msbuild/issues/2455
Note the trailing Prop=1 is required to get MSBuild to invalid it's cache of the project target imports
-->
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Restore" Properties="Configuration=$(Configuration);Version=$(Version);IsInnerBuild=true;Prop=1" />
<!-- Have to use dotnet build instead of another call to MSBuild because of another bug that prevents proper imports within the same physical process -->
<Exec Command="dotnet build /p:Configuration=$(Configuration) /p:Version=$(Version) /p:IsInnerBuild=true" />
<Message Text="Finished inner build" Importance="high" />
</Target>
<Target Name="Restore" />
<Target Name="RemoveBin">
<RemoveDir Directories="bin" />
</Target>
<!-- Don't do real cleans old rebuild since it breaks MSBuild due to the same above bug -->
<Target Name="Rebuild" DependsOnTargets="RemoveBin;Build">
</Target>
</Project>
Treat ProjectReference as PackageReference or allow PackageReference to local csproj
If I understand you correct, you want to generate the package with project MyPackage, then install it to the test project MyConsumer and have the build asset props and targets imported from MyPackage at build time.
To accomplish this goal, you need to complete the following few things:
Make sure the project MyPackage build before the project MyConsumer.
Set the package into the packager source
Add the package MyPackage.nupkg to the test project MyConsumer during the build time.
Details for above:
Make sure the project MyPackage build before the project MyConsumer.
Since you wan to test the package which generated by the project MyConsumer, you should make sure this package grnerate before test project using it, so we need set the project MyConsumer reference the the project MyPackage.
Set the package into the packager source
You can use a post-build event for the project MyPackage to copy the package MyPackage.nupkg to the local feed, or you can just add the bin directory of MyPackage.nupkg to the package source.
Add the package MyPackage.nupkg to the test project MyConsumer during the build time.
Using VS 2017 and the PackageReference style of the test project MyConsumer, you can set a Directory.Build.props file into the root of your solution containing the test project MyConsumer you need:
<Project>
<ItemGroup>
<PackageReference Include="MyPackage" Version="1.0.* />
</ItemGroup>
</Project>
This will add these NuGet packages to the test project MyConsumer in the solution, it will be used as a PackageReference from some remote nuget source.
Check the Martin`s answer for some more details.
Hope this helps.
Is there any way to force dotnet pack to include all referenced assemblies (all dependencies in project.json)?
I believe this is related:
https://github.com/dotnet/cli/issues/1290
https://github.com/dotnet/cli/issues/3959
As of 2020 there is no officially supported way to do this. However various people have come up with ways to achieve it, and the current best way is to install a NuGet package prepared by the amazing Teroneko. Then all you need to do is edit your .csproj to update all your project to be flagged with PrivateAssets="all", as per the package README.
If you are unable to install the aforementioned NuGet package, you can achieve the same effect by editing by editing your .csproj to include the following (once again, this was discovered by Teroneko - it's essentially what the NuGet package he created does):
<Project>
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<!-- Filter out unnecessary files -->
<_ReferenceCopyLocalPaths Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/>
</ItemGroup>
<!-- Print batches for debug purposes -->
<Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = #(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'#(_ReferenceCopyLocalPaths)' != ''" />
<ItemGroup>
<!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. -->
<BuildOutputInPackage Include="#(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/>
</ItemGroup>
</Target>
</Project>
As with the package, you then mark the depended-upon project reference(s) in your .csproj with PrivateAssets="all", and it Just Works(tm).
I was looking for this answer and was annoyed when I couldn't find an obvious one. The solution that worked best for me was to create a nuspec, add the list of DLLs I wanted in the nupkg to that spec and then build with dotnet pack. I created an easy sample and readme here - nuget sample app
Another solution to the problem is to create a custom .targets file to include in your projects. You can add some msbuild instructions to include the files that you need in the package. There is some documentation here on how to do it, here a short example
<PropertyGroup Condition="$(PackAsComponent) != ''">
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CustomBuildOutput</TargetsForTfmSpecificBuildOutput>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);CustomContentInPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="CustomBuildOutput">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)*.dll" Exclude="$(TargetPath)" />
<BuildOutputInPackage Include="$(OutputPath)*.pdb" />
<BuildOutputInPackage Include="$(OutputPath)*.exe" Exclude="$(TargetPath)" />
</ItemGroup>
</Target>
<Target Name="CustomContentInPackage">
<ItemGroup>
<TfmSpecificPackageFile Include="abc.txt">
<PackagePath>mycontent/$(TargetFramework)</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
Basically I activate this when I set the PackAsComponent property in my project.
This preserve the "dotnet pack" functionality 100% without the need to specify any parameter.
As I've installed Octopus build tools on my build system I use octo pack to create the packages. Although this is basically the same thing as just calling good old nuget.exe.
https://octopus.com/docs/packaging-applications/create-packages/octopus-cli
I hope this will help you.
nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects
or your command whatever.
I have been using Gulp to minify and concat my scripts files and complie my SASS files to css.
We are hosting our files on Visual Studio Team Services and Im trying to use the new Visual studio 2015 build system.
Everything works fine and I'm able to call my gulp task and its runs with no issues.
The problem is because the files created are not part of the project, they are not included in my deployment package.
I was wondering if anyone else had same problem and found the way to include these files.
Thansk.
You can add following section to your project file to include the extra files:
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="<<<ExtraFilesToInclude>>>" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
Refer to this article for details: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files
When installing Umbraco as a NuGet package only the umbraco folder is included into the Visual Studio project, but not the umbraco_client folder. The reason for this is that the contents of the umbraco_client folder shouldn't be referenced from Visual Studio. But when publishing the website with Web Deploy I need to have the umbraco_client folder deployed.
One solution is to include the umbraco_client folder into the VS project. The downside to this solution is that upgrading Umbraco via NuGet gets annoying and error prone. You have to remember to exclude and re-include the umbraco_client folder into the project.
So is there a better approach?
You can add the following MSBuild script to the .csproj file.
<Project>
...
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles"]]>
<ItemGroup>
<_umbraco_client_files Include="umbraco_client\**\*" />
<FilesForPackagingFromProject Include="%(_umbraco_client_files.Identity)"]]>
<DestinationRelativePath>umbraco_client\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>
If you want to automate the process of adding the above code into all new Umbraco projects you can create your own NuGet package. Firstly have Umbraco as a dependency. Then add a Build folder and then a .targets file. In the .targets file you add the above code.
For details on the MSBuild script see this article: http://blog.samstephens.co.nz/2010-10-18/msbuild-including-extra-files-multiple-builds/