Following works fine but it does not copy the .pdb file for Asp.net Core 2.0 project.
<ProjectReference Include="..\ProjectA\ProjectA.csproj">
<Project>{b402782f-de0a-41fa-b364-60612a786fb2}</Project>
<Name>ProjectA</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Targets>Build;DebugSymbolsProjectOutputGroup</Targets>
</ProjectReference>
https://blogs.msdn.microsoft.com/kirillosenkov/2015/04/04/how-to-have-a-project-reference-without-referencing-the-actual-binary
So, what should we do for copying the pdb file?
So, what should we do for copying the pdb file?
Just as Marc and that bolg pointed out this method not work in the Visual Studio to copy the .pdb file. Because we set <ReferenceOutputAssembly>false</ReferenceOutputAssembly>, the project reference without referencing the actual binary, VS/MSBuild will not copy the .pdb file.
many people have asked how to also copy the .pdb file in addition to
the .exe/.dll. Turns out there is a trick, but it doesn’t work when
building in VS. But it’s OK since you don’t really need the .pdb in VS
anyway, since the debugger will find the .pdb at its original path
anyway.
If you still want to copy this .pdb file, you can use MSBuild copy task or a build event for your project:
MSBuild copy task:
To accomplish this, unload your project. Then at the very end of the project, just before the end-tag , place below scripts:
<Target Name="CopyPDBfile" AfterTargets="Build">
<Copy SourceFiles="$(SolutionDir)ProjectA\bin\Debug\ProjectA.pdb" DestinationFolder="$(TargetDir)" />
</Target>
Build event:
Add following build command line in the Pre-build/Post-build event:
xcopy /y "$(SolutionDir)ProjectA\bin\Debug\ProjectA.pdb" "$(TargetDir)"
Note: Do not ignore double quotes and spaces in the build command line.
Hope this helps.
Related
Visual Studio creates two files along with the .exe for my project that are required to run the exe: a deps.json and a runtimeconfig.json. A second project in my solution has the first project as a project reference, but those two files aren't being copied to my second project's output directory. How can I tell Visual Studio that it should copy these files into the output directory of the second project, because the referenced project depends on them?
Output directory of my first project:
Foo.exe
Foo.deps.json
Foo.runtimeconfig.json
Output directory of my second project:
Bar.exe
Foo.exe
Should contain deps and runtimeconfig files, but does not
The solution I found is to manually edit my .csproj file to add the following target:
<Target Name="AddRuntimeDependenciesToContent"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"
BeforeTargets="GetCopyToOutputDirectoryItems"
DependsOnTargets="GenerateBuildDependencyFile;
GenerateBuildRuntimeConfigurationFiles">
<ItemGroup>
<ContentWithTargetPath Include="$(ProjectDepsFilePath)"
Condition="'$(GenerateDependencyFile)' == 'true'"
CopyToOutputDirectory="PreserveNewest"
TargetPath="$(ProjectDepsFileName)" />
<ContentWithTargetPath Include="$(ProjectRuntimeConfigFilePath)"
Condition="'$(GenerateRuntimeConfigurationFiles)' == 'true'"
CopyToOutputDirectory="PreserveNewest"
TargetPath="$(ProjectRuntimeConfigFileName)" />
</ItemGroup>
</Target>
This solution came from https://github.com/dotnet/sdk/issues/1675#issuecomment-658779827.
There were other somewhat similar solutions posted in that thread, but this is the only one that worked for me. The others would either not consistently copy the files to my second project, or cause the first project to fail to build due to attempting to access a file that didn't yet exist. The key difference with this one is the inclusion of the correct "BeforeTargets" property (and possibly also "DependsOnTargets"), controlling at which point in the build process the files are included.
I am using csproj file to bundle Chrome windows edition into our ASP.NET Core app. I place all the needed files into $(ProjectDir)\chrome-win and use below XML to copy the files in csproj
<None Update="chrome-win\**" CopyToPublishDirectory="Always" CopyToOutputDirectory="PreserveNewest" LinkBase="chrome-win\" />
What is strange is that when I publish the project using the built in folder publish profile, all the *.dll files gets copied to bin\chrome-win\ and other files are in chrome-win\. This is so frustrating, how can I tell stupid MSBuild / Visual Studio to not to do this? When I build it, the behavior is even stranger, the *.dll files gets copied twice, once to chrome-win folder, also gets copied to bin folder.
I am using the latest VS 2019 and MSBuild
I believe you would want to use the $(BaseOutputPath) property for your copy so that everything writes into the same folder. So it would look like this.
<None Update="chrome-win\**" CopyToPublishDirectory="Always" CopyToOutputDirectory="PreserveNewest" LinkBase="$(BaseOutputPath)\chrome-win\" />
EDIT1:
If you want all the contents of the bin folder moved to \bin\chrome-win\ you could use the CopyTask
<Copy SourceFiles="$(BaseOutputPath)\*" DestinationFiles="$(BaseOutputPath)\" AfterTargets="AfterBuild" />
You might need to tweak this a bit but it should do what you need.
I have a Visual Studio 2008 C#/.NET 3.5 project with a post build task to ZIP the contents. However I'm finding that I'm also getting the referenced assemblies' .pdb (debug) and .xml (documentation) files in my output directory (and ZIP).
For example, if MyProject.csproj references YourAssembly.dll and there are YourAssembly.xml and YourAssembly.pdb files in the same directory as the DLL they will show up in my output directory (and ZIP).
I can exclude *.pdb when ZIP'ing but I cannot blanket exclude the *.xml files as I have deployment files with the same extension.
Is there a way to prevent the project from copying referenced assembly PDB and XML files?
I wanted to be able to add and remove referenced assemblies in my primary application while avoiding the the need to maintain which files I needed to delete or exclude.
I dug through Microsoft.Common.targets looking for something that would work and found the AllowedReferenceRelatedFileExtensions property. It defaults to .pdb; .xml so I explicitly defined it in my project file. The catch is that you need something (whitespace is not sufficient) otherwise it will still use the default.
<Project ...>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
<AllowedReferenceRelatedFileExtensions>
<!-- Prevent default XML and PDB files copied to output in RELEASE.
Only *.allowedextension files will be included, which doesn't exist in my case.
-->
.allowedextension
</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
You can also specify this via the command line:
MsBuild.exe build.file /p:AllowedReferenceRelatedFileExtensions=none
You can add a Post Build event command similar to del "$(TargetDir)YourAssembly*.xml", "$(TargetDir)YourAssembly*.pdb"
top 2 answers didn't work for me. I found a solution in this link which worked for me. http://kitsula.com/Article/How-to-exclude-xml-doc-files-from-msbuild.
Just in case, the above link is not working:
Unload project in Solution Explorer
Right click the project and click 'edit *.csproj'
Add next lines in the PropertyGroup section of each environment.
Reload and rebuild project.
<AllowedReferenceRelatedFileExtensions>
*.pdb;
*.xml
</AllowedReferenceRelatedFileExtensions>
This is a rather old question, but since there is no answer about how to turn off generating PDB and XML files via UI, i figured that it should be here for completeness.
In Visual Studio 2013: in project properties, under compile tab, uncheck "Generate XML documentation file", then click on "Advanced Compile Options" below that and change "Generate debug info" to "None", and that will do the trick.
I didn't have much luck with the other answers, I finally figured out how to do this in my implementation by using the built in "Delete" command, apparently there is a specific way you need to implement wildcards, it's bit nuanced, here's everything you need to be put into your "CSPROJ" (TargetDir is a built in variable, included automatically) under the "Project" tag:
<Target Name="RemoveFilesAfterBuild">
<ItemGroup>
<XMLFilesToDelete Include="$(TargetDir)\*.xml"/>
<PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>
</ItemGroup>
<Delete Files="#(XMLFilesToDelete)" />
<Delete Files="#(PDBFilesToDelete)" />
</Target>
I've also had trouble with various language specific folders being generated, if you have that issue too, you can also remove unused language specific folders too. I've chosen to only trigger this under the build type "Release":
<ItemGroup>
<FluentValidationExcludedCultures Include="be;cs;cs-CZ;da;de;es;fa;fi;fr;ja;it;ko;mk;nl;pl;pt;ru;sv;tr;uk;zh-CN;zh-CHS;zh-CHT">
<InProject>false</InProject>
</FluentValidationExcludedCultures>
</ItemGroup>
<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<RemoveDir Directories="#(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" />
<ItemGroup>
<XMLFilesToDelete Include="$(TargetDir)\*.xml"/>
<PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>
</ItemGroup>
<Delete Files="#(XMLFilesToDelete)" />
<Delete Files="#(PDBFilesToDelete)" />
</Target>
My answer might be trivial now but I'd like to share the BAT script I use to delete the xml files if there's a corresponding dll for it. It's useful if you just want to cleanup the output folder and has other xml files that don't want to remove.
SETLOCAL EnableDelayedExpansion
SET targetDir=%1
ECHO Deleting unnecessary XML files for dlls
FOR %%F IN (%targetDir%*.xml) DO (
SET xmlPath=%%~fF
SET dllPath=!xmlPath:.xml=.dll!
IF EXIST "!dllPath!" (
ECHO Deleting "!xmlPath!"
DEL "!xmlPath!"
)
)
Usage:
Cleanup.bat c:\my-output-folder\
It took me an hour to finish this simple work (thanks to the "delayed expansion" stuff) with all type of searching here and there. Hope it helps other BAT newbies like me.
If you only want to exclude the XML files (for say a debug release) you can do something like this:
<AllowedReferenceRelatedFileExtensions>
<!-- Prevent default XML from debug release -->
*.xml
</AllowedReferenceRelatedFileExtensions>
Basically, each extension (delimited by a semi-colon) listed will be excluded.
Currently, it seems that the default behavior of a VS project is that NuGet-managed dependencies have intermediate files made by NuGet during a compile. Those files are these, in the obj folder:
I like being able to control the name of these output directories (as you can see with Binary and Object), and I'd like to setup my project such that the obj folder isn't used by NuGet to store these files. Is there a way to specify this at the project level or solution level? Maybe an MSBuild XML code snippet? Would be nice.
Any information would be appreciated.
Is there a way to specify this at the project level or solution level?
Maybe an MSBuild XML code snippet? Would be nice.
If you want to change these nuget restore files in another folder, you can try to use Directly.Build.props file to control it.
Solution
1) create a file named Directly.Build.props in your project.
Then add these in this file:
<Project>
<PropertyGroup>
<MSBuildProjectExtensionsPath>$(ProjectDir)Binary\</MSBuildProjectExtensionsPath>
</PropertyGroup>
</Project>
Note: MSBuild Property can only be overwritten by another property. This means that you can overwrite the obj folder as a binary folder. If you want to generate two folders Binary and Object, you can try these:
a) When you try step 1 and then build your project, you can change the property to $(ProjectDir)Object\ in Directly.Build.propsfile and then rebuild again. After that, you will see both of them.
b) do a copy task and please write these in your xxxx.csproj file.
<Target Name="CopyNugetfiles" AfterTargets="Build">
<ItemGroup>
<MySourceFiles Include="$(ProjectDir)Binary\*.*"/>
</ItemGroup>
<Copy
SourceFiles="#(MySourceFiles)"
DestinationFolder="$(ProjectDir)Object\"/>
</Target>
Hope it could help you.
I'm trying to remove a folder (well, actually I thought it was easier to remove the files inside it) from a build using MSBuild scripts.
I thought the way is removing them from the copy task itself, but what I was thinking it was going to see quite straightforward it's not working (I'm sure because I don't have much idea of this stuff, just read documentation yesterday and today). Here is how I'm trying to remove the folder (or the files inside it) ..App_Data/Email Templates with this space (does the space something to do?).
<ItemGroup>
<SourceRootFiles Include="$(BuildFolder)/**/*.*" Exclude="$(BuildFolder)/**/App_Data/Email Templates/*.*">
</SourceRootFiles>
</ItemGroup>
<Target Name="PrepareBuild" DependsOnTargets="CleanUp">
<Message Text="Preparing the build directory : $(LocalBuild)"></Message>
<MakeDir Directories="$(LocalBuild)" />
<Copy SourceFiles="#(SourceRootFiles)" DestinationFolder="$(LocalBuild)\%(RecursiveDir)">
</Copy>
<Exec Command="FOR /r "$(LocalBuild)" %%f IN (.svn) DO RD /s /q "%%f"" IgnoreExitCode="true" />
</Target>
<Target Name="Build" DependsOnTargets="PrepareBuild">
<MSBuild Projects="$(LocalBuild)\Getting.sln" />
</Target>
Update.
Jenkins is raising this error
:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error : Copying file App_Data\Email Templates\BuyerRegistrationComplete.htm to obj\Latest\Package\PackageTmp\App_Data\Email Templates\BuyerRegistrationComplete.htm failed. Could not find a part of the path 'App_Data\Email Templates\BuyerRegistrationComplete.htm'. [C:\Builds\Getting\Latest\Build\Web\UI\UI.csproj]
Dont' really know if it's exluding it or not
On githup is a project named MsBuildTasks that contains all kind of custom-actions that you can easily integrate in your project
https://github.com/loresoft/msbuildtasks
From your update tells a "new" story.
In your project-file you reference files in the App_Data folder which WebDeployment wants to copy to deployment. Removing App_Data results in missing files and thus failure.
Either move those files to another location in your project or remove the references to those files.
My suggestion would be to make a separate folder for the templates, App_Data has a different purpose.