I have the following folder structure:
Library <--[project ref]-- Web Project
-------- -----------
DataFiles
EngineFiles
.cs files .cs files
All files contined both folders have Build Action = Content & Copy To Output Directory = Copy Always. When I build the solution the files are getting created inside the respective folders of the /bin directory (DataFiles & EngineFiles folders).
When I publish locally the files also get created inside the respective folders in the /bin directory of my Web Project.
However when I try to publish via TFS the files flattened inside the /bin folder of my _PublishedWebsites, the DataFiles & EngineFiles folders no longer exist. I am using a custom build template that we have been using without any problems up to this point.
This is what the Target section of our build template looks like:
<Target Name="DropWebSiteUI">
<Message Text="Drop Web Site UI files" />
<CreateItem Include="$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites\StackOverflow\**\*;">
<Output ItemName="WebSiteUI" TaskParameter="Include" />
</CreateItem>
<CreateItem Include="$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)\en-US\*;">
<Output ItemName="ResourceFile_StackOverflowUI" TaskParameter="Include" />
</CreateItem>
<Copy SourceFiles="#(WebSiteUI)" DestinationFiles="#(WebSiteUI->'$(DropLocation)\$(BuildNumber)\WebSiteUI\%(RecursiveDir)%(FileName)%(Extension)')" ContinueOnError="true" />
<Copy SourceFiles="#(ResourceFile_StackOverflowUI)" DestinationFiles="#(ResourceFile_StackOverlowUI->'$(DropLocation)\$(BuildNumber)\WebSiteUI\bin\en-US\%(FileName)%(Extension)')" />
</Target>
Any ideas as to why the folders are not getting copied over with the files included inside them?
Related
I'm trying to achieve the following:-
My feature files are in a separate repo. I include the external repo into my dotnet repo using git subrepo. When i build my dotnet sln, the feature.cs file gets generated at the same location as the .feature file. Basically in the tracked git subrepo folder. I would like my feature.cs file to be generated in a location different from the .feature file location. Can that be done? I'm on .net5.0 and using SpecFlow 3.6.23 (via Specflow.xUnit 3.6.3) and xUnit Test Runner
Feature.cs files will always be generated in the project where the feature file is.
The only option you have is to copy the feature files into the location where you want to have the feature.cs files at the end.
We are doing this in SpecFlow itself, as we copy some feature files from cucumber for testing.
We are doing this with a custom MSBuild Target:
<Target Name="IncludeCucumberMessagesSpecs" BeforeTargets="BeforeUpdateFeatureFilesInProject" Condition="$(DesignTimeBuild) != 'true' OR '$(BuildingProject)' == 'true'">
<Copy SourceFiles="#(CucumberMessagesSpecFlowFeatureFiles)" DestinationFolder="Features/CucumberMessages" />
<ItemGroup>
<_CucumberMessagesSpecFlowFeatureFiles Include="Features/CucumberMessages/*.feature" />
<_CucumberMessagesSpecFlowFeatureFiles>
<CodeBehindFile>Features/CucumberMessages/%(Filename).feature$(DefaultLanguageSourceExtension)</CodeBehindFile>
<Visible>$(UsingMicrosoftNETSdk)</Visible>
</_CucumberMessagesSpecFlowFeatureFiles>
<SpecFlowFeatureFiles Include="#(_CucumberMessagesSpecFlowFeatureFiles)" Exclude="#(SpecFlowFeatureFiles)" />
</ItemGroup>
</Target>
From https://github.com/SpecFlowOSS/SpecFlow/blob/master/Tests/TechTalk.SpecFlow.Specs/TechTalk.SpecFlow.Specs.csproj#L78
I have a bunch of TypeScript files in my project, and I want them all to be copied to the output directory on each build, preserving their structure. Here's what I've tried, but it does not work:
<ItemGroup>
<TypeScriptFiles Include="Scripts\*.ts" />
</ItemGroup>
<Target Name="CopyTypeScriptsToOutput">
<Copy SourceFiles="#(TypeScriptFiles)" DestinationFolder="$(OutputDir)\Scripts" />
</Target>
I've also used Include="Scripts\**\*.ts" but no success. What could be wrong?
I've also used Include="Scripts***.ts" but no success. What could be
wrong?
The contents of the Include are the relative path of the files in your project.
The main problem is that you did not specify how the target runs. If you only use the Build UI to build your project, the target will not run. You should add build dependencies to the target, usually like BeforeTargets and AfterTargets, so that you run the target at build time.
Second, you have a problem with the properties of the target generated path like $(OutputDir). I tried to test this property in vs2015,2017,2019, MSBuild does not have this property by default. If the property is not defined by yourself, the value will never be reached. So I recommend that you can use $(OutputPath) and $(OutputDir).
In addition, please place TypeScriptFiles in the target to prevent confusion when the csproj file is first loaded. If you define it globally, it will be recognized by the system and mapped to the project again.
Sample
This is the target that I successfully completed.
<Target Name="CopyTypeScriptsToOutput" AfterTargets="Build">
<ItemGroup>
<TypeScriptFiles Include="Scripts\*.ts" />
</ItemGroup>
<Copy SourceFiles="#(TypeScriptFiles)" DestinationFolder="$(OutputPath)\Scripts" />
</Target>
Hope it could help you.
in my package.json, I ma using cpx to copy files in the dist folder
"scripts": {
"copy-media": "$(npm bin)/cpx media/**/*.* dist/media",
"build": "tsc && yarn copy-media",
},
So it builds first tsc, and then copy all files from folder media to dist
If I use msbuild to build my project, all the folders not included in my solution are not deployed. Is there a way of deploying the umbraco and umbraco_client folders using msbuild?
I have tried using Targets like:
https://gist.github.com/aaronpowell/6695293
How can we include the files created by ajaxmin in the msdeploy package created by MSBuild
https://blog.samstephens.co.nz/2010/10/18/msbuild-including-extra-files-multiple-builds/
But hey are not being copied to the output folder. Am I missing anything?
You can use a msbuild target(run after the build ends) in which it calls the msbuild copy task to copy necessary files or folders to output folder. Use AfterTargets="build" to let the target run after the build.
A target script which works in my machine looks like this:
<Target Name="Copyumbraco" AfterTargets="build">
<ItemGroup>
<UmbracoFiles Include="$(ProjectDir)**\umbraco\**\*" />
<Umbraco_ClientFiles Include="$(ProjectDir)**\umbraco_client\**\*" />
</ItemGroup>
<Copy SourceFiles="#(UmbracoFiles)" DestinationFolder="$(OutputPath)\%(RecursiveDir)"/>
<Copy SourceFiles="#(Umbraco_ClientFiles)" DestinationFolder="$(OutputPath)\%(RecursiveDir)"/>
</Target>
Using $(ProjectDir) property to define the path, so Msbuild can find those two folders if they are in project folder as you mentioned in comment.
The \%(RecursiveDir) set the msbuild copy task to copy the files to destination path with original folder structure. If what you want to just copy all files to Output folder, you don't need to set it, then the script should be:
<Target Name="Copyumbraco" AfterTargets="build">
<ItemGroup>
<UmbracoFiles Include="$(ProjectDir)**\umbraco\**\*" />
<Umbraco_ClientFiles Include="$(ProjectDir)**\umbraco_client\**\*" />
</ItemGroup>
<Copy SourceFiles="#(UmbracoFiles)" DestinationFolder="$(OutputPath)"/>
<Copy SourceFiles="#(Umbraco_ClientFiles)" DestinationFolder="$(OutputPath)"/>
</Target>
Add the target script into the your project's project file(xx.csproj), make sure you place the script in the format below, then it can work when you use msbuild to build the project.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<Target Name="Copyumbraco" AfterTargets="build">
...
</Target>
</Project>
In addition:
For normal projects like console app, class library, the $(OutputPath) represents the output path. But for web site project, we can use $(WebProjectOutputDir) , hint from Mario!
Try this but fails, earlier use Git repository to deploy web app on Azure using but now want to publish only dist folder using .publishSettings file with Visual Studio 2015 to overcome git command execution on gitbash. Project in .Net Core, Angular 2 with webpack. Try by editing .publishSettings like this
<publishData>
<publishProfile profileName="***** - Web Deploy" publishMethod="MSDeploy" publishUrl="****.scm.azurewebsites.net:443" msdeploySite="****" userName="$***" userPWD="****" destinationAppUrl="http://****.azurewebsites.net" SQLServerDBConnectionString="" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites">
<databases />
</publishProfile>
<publishProfile profileName="***** - FTP" publishMethod="FTP" publishUrl="ftp://***-***-***.azurewebsites.windows.net/site/wwwroot" ftpPassiveMode="True" userName="****\$****" userPWD="*******" destinationAppUrl="http://****.azurewebsites.net" SQLServerDBConnectionString="" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites">
<databases />
</publishProfile>
<Target Name="MoveDistToRoot" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
<!--1.Deleting Folders except dist-->
<ItemGroup>
<_FolderToDelete Include="$(_PackageTempDir)\src" />
<!--you could add more folder paths as follows:-->
<!--<_FolderToDelete Include="$(_PackageTempDir)\folderName" />-->
<_FolderToDelete Include="$(_PackageTempDir)\refs" />
<_FileToDelete Include="$(_PackageTempDir)\*.dll" />
<_FileToDelete Include="$(_PackageTempDir)\web.config" />
</ItemGroup>
<RemoveDir Directories="#(_FolderToDelete)" />
<!--2.Copying files,folders from dist to root directory-->
<ItemGroup>
<_FileToMove Include="$(_PackageTempDir)\dist\**" />
</ItemGroup>
<Move SourceFiles="%(_FileToMove.Identity)" DestinationFolder="$(_PackageTempDir)\%(RecursiveDir)" />
<!--3.Deleting the empty folder dist-->
<RemoveDir Directories="$(_PackageTempDir)\dist" />
</Target>
</publishData>
When Publish using File System folder structure look like this
and dist folder
How to only deploy dist folder to azure web site using .PublishSettings file
If you only want to deploy dist folder, you could right click this folder and choose Publish dist menu. It will only deploy the dist folder to your web server or folder which defined in the publish setting file.
Is there a generic way I can get a post-build event to copy the built assembly, and any .config and any .xml comments files to a folder (usually solution relative) without having to write a post-build event on each project in a solution?
The goal is to have a folder that contains the last successful build of an entire solution.
It would be nice to use the same build solution over multiple solutions too, possibly enabling/ disabling certain projects (so don't copy unit tests etc).
Thanks,
Kieron
You can set common OutputPath to build all projects in Sln in one temp dir and copy required files to the latest build folder. In copy action you can set a filter to copy all dlls without "test" in its name.
msbuild.exe 1.sln /p:Configuration=Release;Platform=AnyCPU;OutputPath=..\latest-temp
There exists more complicated and more flexible solution. You can setup a hook for build process using CustomAfterMicrosoftCommonTargets. See this post for example.
Sample targets file can be like that:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
PublishToLatest
</BuildDependsOn>
</PropertyGroup>
<Target Name="PreparePublishingToLatest">
<PropertyGroup>
<TargetAssembly>$(TargetPath)</TargetAssembly>
<TargetAssemblyPdb>$(TargetDir)$(TargetName).pdb</TargetAssemblyPdb>
<TargetAssemblyXml>$(TargetDir)$(TargetName).xml</TargetAssemblyXml>
<TargetAssemblyConfig>$(TargetDir)$(TargetName).config</TargetAssemblyConfig>
<TargetAssemblyManifest>$(TargetDir)$(TargetName).manifest</TargetAssemblyManifest>
<IsTestAssembly>$(TargetName.ToUpper().Contains("TEST"))</IsTestAssembly>
</PropertyGroup>
<ItemGroup>
<PublishToLatestFiles Include="$(TargetAssembly)" Condition="Exists('$(TargetAssembly)')" />
<PublishToLatestFiles Include="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" />
<PublishToLatestFiles Include="$(TargetAssemblyXml)" Condition="Exists('$(TargetAssemblyXml)')" />
<PublishToLatestFiles Include="$(TargetAssemblyConfig)" Condition="Exists('$(TargetAssemblyConfig)')" />
<PublishToLatestFiles Include="$(TargetAssemblyManifest)" Condition="Exists('$(TargetAssemblyManifest)')" />
</ItemGroup>
</Target>
<Target Name="PublishToLatest"
Condition="Exists('$(LatestDir)') AND '$(IsTestAssembly)' == 'False' AND '#(PublishToLatestFiles)' != ''"
DependsOnTargets="PreparePublishingToLatest">
<Copy SourceFiles="#(PublishToLatestFiles)" DestinationFolder="$(LatestDir)" SkipUnchangedFiles="true" />
</Target>
</Project>
In that targets file you can specify any actions you want.
You can place it here "C:\Program Files\MSBuild\v4.0\Custom.After.Microsoft.Common.targets" or here "C:\Program Files\MSBuild\4.0\Microsoft.Common.targets\ImportAfter\PublishToLatest.targets".
And third variant is to add to every project you want to publish import of custom targets. See How to: Use the Same Target in Multiple Project Files