I'm developing web service that and later publish it using VS wizard. My service uses external dll that also should be published. How to tell system to publish dll to web services bin folder.
I assume when you publish VS has created *.pubxml file inside your Properties folder, for example I am using VS 2015 for MVC 4.5 and below is my location where my *.pubxml file is found.
You can edit this xml file as explained in ASP.NET Web Deployment using Visual Studio: Deploying Extra Files and add your extra DLLs folder here.
If you add reference to your external dlls and use anything inside the dll, that dll will be automatically copied to the bin folder together with your dll.
In case your dlls are loaded dynamically, you can try adding this to your .csproj file:
<Target Name="AdditionalPublish" AfterTargets="AfterPublish">
<Copy SourceFiles="" DestinationFolder="$(OutputPath)" />
</Target>
Specify SourceFiles with what you want to publish: https://msdn.microsoft.com/en-us/library/3e54c37h.aspx
For example, let's say you want to copy these dlls:
<ItemGroup>
<ExternalFiles Include="lib1.dll;lib2.dll;lib3.dll"/>
</ItemGroup>
<Target Name="AdditionalPublish" AfterTargets="AfterPublish">
<Copy
SourceFiles="#(ExternalFiles)"
DestinationFolder="$(OutputPath)"
/>
</Target>
Related
I'm developing a solution containg multiple web projects that share static content like javascript files.
I've done some research and it seems that proper way of handling it is to add shared files as solution items and then add them as links to web projects:
Then web projects should implement copying these files to output directory (I set them to Content beforehand):
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="%(Content.Link)"
OverwriteReadOnlyFiles="true"
ContinueOnError="true"
Condition="'%(Content.Link)' != ''" />
</Target>
</Project>
Unfortunetely it doesn't work. I tried installing the MSBuild.WebApplication.CopyContentLinkedFiles NuGet package, but it didn't help.
I tried setting Copy to output directory property to Always which make them present in the build:
However scripts were still missing after launching the app from VS:
How can I make this work? I'm looking for a simplest solution possible.
Your setup potentially will work for publish scenarios but for development environment it won't - the wwwroot folder from the project root (i.e. WebApp1\wwwroot and WebApp2\wwwroot) is used to serve the static files, so you need to copy the shared file there on build (possibly exclude it from git also for convenience).
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.
We have a c# framework (not .core) solution with several projects in it. It is build by TFS. Sometimes (not all the times) I got a build error:
error MSB3030: Could not copy the file
"c:\BuildAgent_work\27\b\Console.Admin\Product.Admin.exe.manifest"
because it was not found.
[c:\BuildAgent_work\27\s\Console.Admin\Console.Admin.csproj]
The app.manifest file is added to the project Properties folder, and I checked it exists on buildagent source folder. I checked it is not exists on the binaries folder. I don't know why it is not copied there during the build.
In fact I don't know if I need this manifest thing at all. I think I don't. This whole thing was added to the project by one of my collegaue for a reason is unknown for me. Is it required to create publish package for web projects? In this case why it is required for a console project? For what reason is it added?
The msbuild parameters (for building the solution) are the following, and the [x] Clean option is checked in the TFS build solution step.
/p:OutDir=$(Build.BinariesDirectory)
/p:GenerateProjectSpecificOutputFolder=true
/p:DeployOnBuild=true /
p:PackageAsSingleFile=true
/p:GenerateDocumentation=true
/p:DisableAllVSGeneratedMSDeployParameter=true
/t:Clean,Build,Publish
/p:RunCodeAnalysis=$(CodeAnalysis.Run);CodeAnalysisRuleSet=$(CodeAnalysis.RuleSet).ruleset;CodeAnalysisIgnoreGeneratedCode=true
/p:IncludeAppPool=true
/p:PrecompileBeforePublish=true;EnableUpdateable=false
An application manifest is an XML file that describes and identifies the shared and private side-by-side assemblies that an application should bind to at run time. These should be the same assembly versions that were used to test the application. Application manifests may also describe metadata for files that are private to the application. You can refer to this document.
So, you first need to check in csproj for any additional operations on the manifest. When the MSBuild creates the publish files it copies files base on the build definition , you can try to edit the .csproj file as bellow which copied the relevant files. app.manifest is your file path .
<ItemGroup>
<None Update="app.manifest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
I have a config file in my C# project that is excluded from source control (it's local to each developer). However, if the file doesn't exist I want it to be copied from the corresponding ".template" file (which is in source control). To do this, I added an MSBuild item type and target, like this:
<ItemGroup>
<AvailableItemName Include="LocalConfigTemplate" />
</ItemGroup>
<Target Name="CopyFromTemplateIfNeeded" BeforeTargets="BeforeBuild" Inputs="#(LocalConfigTemplate)" Outputs="#(LocalConfigTemplate->'%(FileName)')">
<Copy Condition="!Exists(%(LocalConfigTemplate.Filename))" SourceFiles="#(LocalConfigTemplate)" DestinationFiles="#(LocalConfigTemplate->'%(FileName)')" />
</Target>
(Based on How to hide files generated by custom tool in Visual Studio) This is in a separate file, included from the project file (before Microsoft.CSharp.targets, if that matters).
It works, but when I delete the target file (local.config) and build the project VS thinks it's "up to date" and does not build. How do I get it to detect that the output file is missing and build in that case?
Try doing a Clean before the rebuild, maybe Visual Studio is picking the file up from the bin directory.