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.
I want to copy a file to 2 output directories using csproj dotnetcore. I use this code, but it just copies the file to the 2nd directory.
<Content Include="lock_screen_linux.desktop" CopyToPublishDirectory="PreserveNewest">
<LinuxPath>/usr/share/applications/lock_screen_linux.desktop</LinuxPath>
<LinuxPath>/etc/xdg/autostart/lock_screen_linux.desktop</LinuxPath>
</Content>
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.
I'm frequently adding a lot of content files (mostly images and js) to my ASP.NET project. I'm using VS publish system, and on publish, new files are not published until I include them in the project. I would like to auto include all files in specified directory. Is there a way to specify which directories should be auto-included in csproj file or anywhere else?
Old thread, I know, but I found a way to do this that I keep forgetting, and on my search to find it one last time, I stumbled upon this question. The best way I've found to this is is to use the BeforeBuild target in the .csproj file.
<Target Name="BeforeBuild">
<ItemGroup>
<Content Include="**\*.less" />
</ItemGroup>
</Target>
VS 2010 won't touch this section, and it ensures that your files are included as content every time the project is built.
You simply can extend your website .csproj file. Just add your content root folder with a recursive wildcard:
...
<ItemGroup>
<!-- your normal project content -->
<Content Include="Default.aspx" />
<!-- your static content you like to publish -->
<Content Include="Images\**\*.*" />
</ItemGroup>
...
Doing so makes this folder and all content below visible inside your solution browser.
If you try to hide the folder inside the solution browser by specifying
<Content Include="Images\**.*.*">
<Visible>false</Visible>
</Content>
it will not be published.
Update
As you already discovered the wildcard will be replaced as soon as you touch the folder inside your solution because VS projects are not designed to contain arbitrary content.
So you will have to make sure the folder and its contents are never modified from within VS - adding or removing files can only be done on the file system ... which is what you wanted as i understood your question.
It would be easier if the folder could be hidden in VS but i couldn't find a way to hide it AND publish.
Another unsuccessful approach was to include the folder by a CreateItem Task.
This resulted in the contents of folder being published to \bin\app.publish\... and could not be convinced to publish it together with the content items inside the .csproj so i did not present it in my answer.
For those having issues using Chris' answer, this is the solution for Visual Studio 2012 and newer:
<Target Name="ContentsBeforeBuild" AfterTargets="BeforeBuild">
<ItemGroup>
<Content Include="images\**" />
</ItemGroup>
</Target>
As Chris mentioned in his answer - Visual Studio will not touch this <Target> section, even if you manually fiddle around (adding/removing files) with the target directory.
Please note that you should include a subdirectory where the files are located (in the case above, it's images). Visual Studio/MSBuild will place those files in the same directory within the project structure. If you don't use a subdirectory, the files will be placed at the root of the project structure.
For a quick explanation of the wildcards:
** means everything recursively (files, subdirectories, and files within those)
*.ext will include all files with extension ext within the top-level directory, but not subdirectories
For example, *.ext could be *.png, *.js, etc. Any file extension will work
**\*.ext will include all files with extension ext from the top-level directory and all subdirectories.
See the answer from How do I use Nant/Ant naming patterns? for a more complete explanation with examples.
For completion, please note that there is a difference between using <Target> and not using it.
With the <Target> approach, Visual Studio will not show the files within the Solution Explorer.
<Target Name="ContentsBeforeBuild" AfterTargets="BeforeBuild">
<ItemGroup>
<Content Include="images\**" />
</ItemGroup>
</Target>
The non-<Target> approach will instruct Visual Studio to show the files within the Solution Explorer. The drawback with this one is that any manipulation of the automatic directories will cause Visual Studio to override the wildcard entry. It should also be noted that the approach below will only update the Solution Explorer upon opening the Solution/Project in VS. Even the Solution Explorer's "refresh" toolbar button won't do it.
<ItemGroup>
<Content Include="images\**" />
</ItemGroup>
You can use the framework's System.IO.Directory.GetFile(string) method and its overloads to recursively include all files.
<ItemGroup>
<Content Include="$([System.IO.Directory]::GetFiles('$(ProjectDir)Scripts\', '*.js', SearchOption.AllDirectories))" />
<Content Include="$([System.IO.Directory]::GetFiles('$(ProjectDir)Images\', '*.png', SearchOption.AllDirectories))" />
</ItemGroup>
I've written up how I was able to get the content includes created with a small powershell script:
$folders = Get-ChildItem .\ -r -Directory
$filtered = $folders |Select-Object #{Name='FullName';Expression={$_.fullname.replace($pwd,'')}}, #{Name='FolderDepth';Expression={($_.fullname.Split('\').Count) - ($Pwd.Path.split('\').count)}} | Sort-Object -Descending FullName,folderDepth
$basefolders = $filtered | Where-Object{$_.folderdepth -eq 1}
$basefoldersobj = #()
foreach($basefolder in $basefolders)
{
$basefoldername =$baseFolder.fullname
$filteredbase = $filtered -match "\$basefoldername\\" | Sort-Object -Descending FolderDepth | Select-Object -first 1
if($filteredbase -eq $null)
{
$filteredbase = $filtered -match "\$basefoldername" | Sort-Object -Descending FolderDepth | Select-Object -first 1
}
$obj = New-Object psobject
Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Folder' -Value $basefolder.fullname.trim('\')
Add-member -InputObject $obj -MemberType NoteProperty -Name 'DeepestPath' -Value $filteredbase.folderDepth
$basefoldersobj += $obj
}
$include = '*.*'
foreach($bfolderObj in $basefoldersobj)
{
$includecount = ''
$includecount = "\$include" * ($bfolderObj.Deepestpath)
Write-Output "<content Include=`"$($bfolderObj.folder)$includecount`" /> "
}
This should produce the necessary include statement at the powershell prompt
You can add files with links like this, they are searchable, view-able, but they do not checkout if you try to change them, also visual studio leaves the wildcards in place:
<ItemGroup>
<Content Include="..\Database Schema\Views\*.sql">
<Link>Views\*.sql</Link>
</Content>
</ItemGroup>
This goes inside the .proj file.
Not to my knowledge; however my suggestion is to paste them into the project as this will include them by default. So, instead of pasting them into the directory via Explorer, use Visual Studio to paste the files into the folders.
You can add folder with files recursively like this:
<ItemGroup>
<Content Include="somefolder\*.txt">
<Link>%(RecursiveDir)myown_somefolder\%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>
I realized that best solution for this is manually add files, one by one. If you have hundreds of them as I did it was just a matter of few hours. Funny that even in 2016 with VS 2015 this serious problem is still not solved. Ahh, how I love Xcode.
I'm currently using Subversion to manage my ASP.NET website. I'm finding that whenever I go to upload my website to my server, I'm copying a large number of hidden .svn folders and whatever contents may lie within them.
Does anyone have any suggestions for avoiding this? I don't particularly want those hidden .svn folders on the production server, but short of manually deleting each .svn folder before I upload my website, I'm at a loss for how to have a .svn-folder-free production environment.
Edit: Thank you everyone, those are great suggestions, I really appreciate it!
You should use export command of the subversion.
You may tweak registry and add a "Delete SVN Folders" to the context menu for folders. Here is an example script from http://weblogs.asp.net/jgalloway/archive/2007/02/24/shell-command-remove-svn-folders.aspx Save it to a .reg file and execute.
Right click on your project folder and delete all .svn folders recursively.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
#="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
#="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
two suggestions:
Use robocopy or xcopy to filter out the .svn folders
svn export the repository to the webserver (docs). Exporting will not write any .svn folders
see also: Tortoise SVN hidden SVN folders
How about you run Subversion on the server and then do an svn export from the repository? svn export is like a checkout, but w/o the .svn folders (and w/o the ability to do Subversion work in that directory).
Alternately, do a svn export of the repo on your local machine and then FTP up the exported version.
I have a postbuild step, which prepares a clean drop folder as part of the project build. Here's how I do it:
<PropertyGroup>
<DropPath>..\..\drop\</DropPath>
<TestDropPath>..\..\test\</TestDropPath>
</PropertyGroup>
<Target Name="AfterBuild">
<ItemGroup>
<Binaries Include="$(OutputPath)**\*.*" />
</ItemGroup>
<ConvertToAbsolutePath Paths="$(DropPath)">
<Output TaskParameter="AbsolutePaths" ItemName="FullDropPath" />
</ConvertToAbsolutePath>
<Message Importance="High" Text="Binplacing -> #(FullDropPath)" />
<Copy SourceFiles="#(Compile)" DestinationFiles="#(Compile->'$(DropPath)%(Identity)')" />
<Copy SourceFiles="#(Content)" DestinationFiles="#(Content->'$(DropPath)%(Identity)')" />
<Copy SourceFiles="#(EntityDeploy)" DestinationFiles="#(EntityDeploy->'$(DropPath)%(Identity)')" />
<Copy SourceFiles="#(Binaries)" DestinationFiles="#(Binaries->'$(DropPath)%(Identity)')" />
</Target>
Of course, svn export works as well. :-) However, with that approach you can't modify and commit back to the repository any source file modified during the build.