I'm trying to figure out how to upload a folder that i do not want to reference in the project file. The folder "build" is and output step that is generated from webpack. I've found other threads with the same problem and this is what i've tried (added to the end of my pubxml file:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="..\build\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>build\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
which did not work
Try "CopyAllFilesToSingleFolderForMSDeployDependsOn" instead of "CopyAllFilesToSingleFolderForPackageDependsOn".
<PropertyGroup>
<CopyAllFilesToSingleFolderForMSDeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMSDeployDependsOn);
</CopyAllFilesToSingleFolderForMSDeployDependsOn>
</PropertyGroup>
Based on my review of the latest MSDeployAddFilesOutsideOfProject.wpp.targets file (distributed with VS2015), "ForPackage" may be deprecated. The target is still there but I can't find where its referenced.
Update - Wrote a quick blog post with more details:
http://www.dotnetcatch.com/2016/07/20/include-extra-files-in-webdeploy-package/
Related
How to patch Asp.Net Core project (csproj) in order to build versioned binaries with AppVeyor?
Is there a way to apply versioning separately for AssemblyVersion and FileVersion?
AppVeyor has predefined step to patch AssemblyInfo.cs file, but it isn't included into project and functionality of AssemblyInfo moved to csproj file, therefore it's not clear how to deal with versioning.
Appreciate you help!
As .NET Core .csproj is a regular XML you can use PowerShell script to update the version information in it. For example, you might have the following MyProject\MyProject.csproj:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<Version>1.2.3.4</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
</ItemGroup>
</Project>
Then on AppVeyor the script patching <Version> would be the following:
$xmlPath = "$env:appveyor_build_folder\MyProject\MyProject.csproj"
$xml = [xml](get-content $xmlPath)
$propertyGroup = $xml.Project.PropertyGroup | Where { $_.Version}
$propertyGroup.Version = $env:appveyor_build_version
$xml.Save($xmlPath)
I have a web application project that I want to publish to a web server. There is a folder of files that are not included in the project, but need to be copied when it is published. I found a few posts on how to do this copying with MSBuild, but I cannot get it to copy all files/folders recursively in the main folder I want to copy.
The folder I want to copy is (proj)/Scripts. (This directory is excluded from the application project because I have all my JavaScript code in a separate project in the same solution, and this folder is copied from the JS project's output folder after it performs minification and other build tasks.)
Here is the section I have added to my *.csproj file:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="Scripts\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>
<!-- whitespace and new line added for question readability -->
Scripts\%(RecursiveDir)%(Filename)%(Extension)
</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
This will copy any files in the top level of the /Scripts folder, but nothing in its subfolders.
How do I make it recursive?
Fixed my own problem:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="Scripts\**\*.*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>Scripts\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<_CustomFiles Include="Scripts\*" /> had to be changed to
<_CustomFiles Include="Scripts\**\*.*" />
This worked for me:
<ItemGroup>
<Content Include="YourTargetDir\**\*.*">
<Link>YourTargetDir\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
I'm trying to include a file in an ASP.NET filesystem publish that's not included in the solution (it's autogenerated from a post-build script). According to these instructions, I should be able to add a reference to the file in my .pubxml definition using the <_CustomFiles> element. Here's what my .pubxml file looks like:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>(publish URL here)</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="scripts\app.min.js" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>
The second <PropertyGroup> and the <Target> elements were added by me.
However, Visual Studio isn't recognizing the <_CustomFiles> element and the file isn't being included in the publish. Notice the green squiggly line underneath the element:
When I hover over it, the following error message is shown:
The element 'ItemGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element '_CustomFiles' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'
Why is this element not recognized by Visual Studio? What do I need to change in order to include this file in my filesystem publish?
Figured it out. I misunderstood the purpose of the <_CustomFiles> element. It seems this is a custom element (i.e. not part of the XML schema, hence the VS warning) used to pass information to the <FilesForPackaginFromProject> element below it.
It turns out this method was working for me, I was simply using the relative paths incorrectly.
I have a nuget package that contains an build target file that add files when the project is published to Azure.
I've gotten this to work, but if I press the "Start Preview" button in the publish dialog before I press publish, the nuget-package-files are not published and if they exist on the server they are deleted.
This is the content of the build target file
<ItemGroup>
<LisaFrontendFiles Include="$(MSBuildThisFileDirectory)..\Web\**\*" />
<NativeBinaries Include="$(MSBuildThisFileDirectory)..\lib\native\*" />
</ItemGroup>
<Target Name="LisaFrontendPublishTarget" BeforeTargets="CopyAllFilesToSingleFolderForPackage">
<ItemGroup>
<FilesForPackagingFromProject Include="%(LisaFrontendFiles.Identity)">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
<ItemGroup>
<FilesForPackagingFromProject Include="%(NativeBinaries.Identity)">
<DestinationRelativePath>bin/%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
LisaFrontendPublishTarget;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
I have a solution which include loosely coupled projects with a ASP.Net MVC application. I have set the output of all projects to 'MvcProject\bin' folder. So, I need to Clean/Rebuild the solution before I will be able to run my web application. The problem is that when I publish this to Azure or Local system then it will not include all the project dlls(and its dependent dlls, it will only include MvcProject and its dependent dlls). Is there is any way to tell the VS(or msbuild) to clean/rebuild the solution and include all the related project dlls which output is set to 'MvcProject\bin'
This is what I did. First of all edited all my class-library projects csproj file OutPath to,
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
..................................
<OutputPath>bin\Debug\</OutputPath>
..................................
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
..................................
<OutputPath>bin\Release\</OutputPath>
..................................
Next add this to my MVC application csproj file bottom(before </Project>),
<Target Name="AfterBuild">
<ItemGroup>
<_CustomFiles Include="..\Project1\bin\$(Configuration)\**\*;..\Project2\bin\$(Configuration)\**\*" />
................................................................
</ItemGroup>
<Copy SourceFiles="#(_CustomFiles)" DestinationFiles="#(_CustomFiles->'bin\%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
Finally add this to my Azure.pubxml(you can find it in Properties/PublishProfiles) file bottom(before </Project>),
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="..\Project1\bin\$(Configuration)\**\*;..\Project2\bin\$(Configuration)\**\*" />
................................................................
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>