I currently have
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)Shared.Lib\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
I want to do something like this, but one level above $(SolutionDir)
You can use ..\ to move up a directory.
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)..\Shared.Lib\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
Solution:
copy "$(TargetPath)" "$(SolutionDir)"..\"Shared.Lib\$(TargetFileName)"
If you have ..\ within the quotation marks, it will take it as literal instead of running the DOS command up one level.
This is not working in VS2010 .. is not resolved but becomes part of the path
Studio is running command something like this copy drive$:\a\b\bin\debug drive$:\a\b..\c
In .Net Core edit csproj file:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y "$(TargetPath)" "$(SolutionDir)"..\"lib\$(TargetFileName)"" />
</Target>
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
xcopy "$(TargerDir)." "$(SolutionDir)..\Installer\bin\"
Note: "../" is used for One level up folder structure
Related
In project i have as normal files as links (shortcuts) to existing file:
In post-build event i want to copy all files, including links (but as real file) to other directory, for example:
"%RELEASEPATH%\Code\"
Using default xcopy command it do copy all files + directory, but not links:
xcopy /E /Y /R "$(ProjectDir)Code" "%RELEASEPATH%\Code\"
If there a way to copy linked files (as real files) with xcopy as well?
I am not sure of xcopy, but if all you want is for copying the link file to the folder you put the link file in, then you can try:
(source from Copying linked content files at each build using MSBuild)
build by adding the following at the end of the .csproj file, just
before the final tag:
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="%(Content.Link)"
SkipUnchangedFiles='true'
OverwriteReadOnlyFiles='true'
Condition="'%(Content.Link)' != ''" />
</Target>
Lets say I have a project solution, I want to copy the contents of bin/Release folder after the build into another folder named "Deploy"
Source: D:\Solution\bin\Release
Destination: D:\Destinationfolder\bin\deploy
the macros are as follows
TargetDir : D:\Solution\bin\Release
ProjectDir: D:\Solution
I have tried this
xcopy /? $(TargetDir) $(ProjectDir)\..\Bin\Deploy /R /Y /S
This is not working. Am I doing anything wrong? Is there any other way to do this?
Remove the /? from the xcopy command, and add quotes around paths. The .. will take the $(ProjectDir) path back to D:, so the Destinationfolder should also be added.
So: xcopy "$(TargetDir)" "$(ProjectDir)\..\Destinationfolder\Bin\Deploy" /R /Y /S
I would suggest you to create a Publish Profile. If you want to build the project to a desired folder you can simply right click on the project and click Publish.
I want to copy all files recursivly with given file extensions after the build process succeeds.
Robocopy
ROBOCOPY %source% %destination% /S *.as?x *.xls? *.mrt
xcopy
xcopy .\*.as?x %destination% /SY
xcopy .\*.xls? %destination% /SY
xcopy .\*.mrt %destination% /SY
I have tried to insert both possibilities in the post build section in visual studio. RoboCopy exits with error: Error 1 The command "ROBOCOPY source destination /S *.as?x *.xls? *.mrt" exited with code 1.
Some files where copied but to the wrong folder (_PublishedWebsites).
xcopy also copy to the wrong directory (_PublishedWebsites) and also does not copy all files.
In the command line both commands work as expected.
Update
I have updated my robocopy command:
ROBOCOPY $(MSBuildProjectDirectory) $(MSBuildProjectDirectory)\..\..\..\EDP\Web\Modules\Invoice\Web /S *.as?x *.xls? *.mrt
Now the files are copied to the correct location, but the return code of robocopy causes an visual studio error.
Here a solution with help of this:
call ROBOCOPY $(MSBuildProjectDirectory) $(MSBuildProjectDirectory)\..\..\..\EDP\Web\Modules\Invoice\Web /S *.as?x *.xls? *.mrt
if %errorlevel% leq 1 exit 0 else exit %errorlevel%
Preferred solution
<ItemGroup>
<SourceFiles Include="$(MSBuildProjectDirectory)\**\*.js"/>
<SourceFiles Include="$(MSBuildProjectDirectory)\**\*.html"/>
<SourceFiles Include="$(MSBuildProjectDirectory)\**\*.css*"/>
<SourceFiles Include="$(MSBuildProjectDirectory)\**\*.png"/>
<SourceFiles Include="$(MSBuildProjectDirectory)\**\*.as?x"/>
</ItemGroup>
<Target Name="AfterBuild">
<Copy
SourceFiles="#(SourceFiles)"
DestinationFiles="#(SourceFiles->'%(MSBuildProjectDirectory)..\..\..\EDP\Web\Modules\DMS\Web\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
I would like to release to distinct flavours of my app and would like to indicate this in the application name displayed on the phone. As far as I know for Silverlight Phone Apps the name is solely determined by WMAppManifest.xml. Therefore I would like to modify the application title at build time based on my Build Configuration. Any suggestions?
You can do this with a bit of T4 templating and code generation (see http://msdn.microsoft.com/en-us/library/bb126445.aspx if you don't know about this.)
The following steps will allow you to use a different application title if you are using the debug or release configuration.
Take a copy of WMAppManifest.xml and rename it to WMAppManifest-base.tt
Change the content of WMAppManifest-base.tt to be
<## template language="C#" #><## output extension=".xml" #><?xml version="1.0"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
<App xmlns="" ProductID="{4c5315b6-4030-46c5-b5ea-17284d6af0c6}" Title="<#= this.ConfiguredAppTitle #>" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="WindowsPhoneApplication8 author" Description="Sample description" Publisher="WindowsPhoneApplication8">
<IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
<Capabilities>
<Capability Name="ID_CAP_IDENTITY_DEVICE"/>
<Capability Name="ID_CAP_NETWORKING"/>
</Capabilities>
<Tasks>
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/>
</Tasks>
<Tokens>
<PrimaryToken TokenID="WindowsPhoneApplication8Token" TaskName="_default">
<TemplateType5>
<BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
<Count>0</Count>
<Title><#= this.ConfiguredAppTitle #></Title>
</TemplateType5>
</PrimaryToken>
</Tokens>
</App>
</Deployment>
<#+
string ConfiguredAppTitle = "MyPhoneApp";
#>
(Adjust capabilities, etc. as appropriate.)
In the same folder as WMAppManifest-base.tt create a file called Debug.WMAppManifest.tt with the following contents:
<#
ConfiguredAppTitle = "MyDebugApp";
#><## include file="WMAppManifest-base.tt" #>
Now create a file called Release.WMAppManifest.tt with the following contents:
<#
ConfiguredAppTitle = "MyReleaseApp";
#><## include file="WMAppManifest-base.tt" #>
Create a file called copyifnewer.bat in the root of the project. Give it the following contents:
echo Comparing: %1 with %2
if not exist %1 goto File1NotFound
if not exist %2 goto File2NotFound
fc %1 %2
if %ERRORLEVEL%==0 GOTO NoCopy
echo Files are not the same. Copying %1 over %2
copy %1 %2 /y & goto END
:NoCopy
echo Files are the same. Did nothing
goto END
:File1NotFound
echo %1 not found.
goto END
:File2NotFound
copy %1 %2 /y
goto END
:END
In the project properties add this PRE-build command:
"$(ProjectDir)\copyifnewer.bat" "$(ProjectDir)properties\$(ConfigurationName).WMAppManifest.xml" "$(ProjectDir)properties\WMAppManifest.xml"
Now you can adjust the values in the debug & release files to alter the titles as you wish.
If you have other configurations just create appropriately named files (with the same contents as the debug.*.tt) and they'll be picked up automatically.
Note that when testing, if you install the app with one name (in the emulator or phone) you'll have to uninstall it to see a name change reflected in the application list.
Note to self: must blog about this. (It's really powerful but hard to work out how to do the first time.)
You can use the pre-build step (Project Properties -> Build Events -> Pre-Build event command line) in the project properties with conditional command-lines to achieve this.
Having files for each version and then copying over the default to replace the data there. You can also set up your icons to use this same system! :)
if $(ConfigurationName) == Phone_Free_Debug (
copy /Y $(ProjectDir)Properties\WMAppManifest_Free.xml $(ProjectDir)Properties\WMAppManifest.xml
copy /Y $(ProjectDir)173x173icon_Free.png $(ProjectDir)173x173icon.png
copy /Y $(ProjectDir)200x200icon_Free.png $(ProjectDir)200x200icon.png
)
if $(ConfigurationName) == Phone_Free_Release (
copy /Y $(ProjectDir)Properties\WMAppManifest_Free.xml $(ProjectDir)Properties\WMAppManifest.xml
copy /Y $(ProjectDir)173x173icon_Free.png $(ProjectDir)173x173icon.png
copy /Y $(ProjectDir)200x200icon_Free.png $(ProjectDir)200x200icon.png
)
if $(ConfigurationName) == Phone_Debug (
copy /Y $(ProjectDir)Properties\WMAppManifest_Paid.xml $(ProjectDir)Properties\WMAppManifest.xml
copy /Y $(ProjectDir)173x173icon_Paid.png $(ProjectDir)173x173icon.png
copy /Y $(ProjectDir)200x200icon_Paid.png $(ProjectDir)200x200icon.png
)
if $(ConfigurationName) == Phone_Release (
copy /Y $(ProjectDir)Properties\WMAppManifest_Paid.xml $(ProjectDir)Properties\WMAppManifest.xml
copy /Y $(ProjectDir)173x173icon_Paid.png $(ProjectDir)173x173icon.png
copy /Y $(ProjectDir)200x200icon_Paid.png $(ProjectDir)200x200icon.png
)
I know this is an old thread now, but came across it as I was looking to do something similar and the accepted answer was spot on for me. I just wanted to add in a suggestion for a modification to the batch file part of it, in case it helps anyone else. I would have commented on the accepted answer but lack the reputation to so far, so hope no-one minds me adding it as a separate answer..!
If you're version-controlling your solution (e.g. in TFS) your WMAppManifest might be write-protected, unless you specifically remembered to check it out prior to build. If it is, the batch file won't be able to overwrite it, but you won't get any notification of it and the build will proceed, meaning you may fail to notice it didn't update per your build configuration. To address this, add the following to the end of the batch file (after :END):
if %errorlevel% neq 0 exit /b %errorlevel%
If the batch file fails, the build will stop, alerting you to the issue.
Also, don't create the batch file in Visual Studio! It'll save in UTF-8 encoding (I think) and you may get errors when Windows tries to shell it. Create it in notepad to ensure it saves in ASCII. If you save it with the wrong encoding and it won't run, the above amend will catch that as well.
I am trying to delete files in my $(TargetDir) within visual studio before building a project.
How do you have to format command line to get around this problem I am getting below?
Try
cd $(TargetDir)
del *.tif
As jvenema pointed out, your $(TargetDir) is expanding into a path containing spaces in the folder names which is breaking the delete command.
I ended up using rd /s /q "$(TargetDir)" to clean out the directory. As far as I know it is working.
Try adding quotes around the directory.
You have to write del "$(TargetDir)*.tif" because of spaces in directory path.
Old question but a couple of things:
del "$(TargetDir)*.tif" /q
1) /q is for quiet. Otherwise, del cmd prompts "... Are you sure (Y/N)?" which the build does not like.
2) As many have pointed out, "" around the targetDir for possible space in the target directory.
For DOTNET Core, your quotes need to be escaped, like this:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="del "$(ProjectDir)wwwroot\_framework\*.*" /q" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy "$(ProjectDir)..\Client\bin\Debug\net5.0\wwwroot\_framework\*.*" "$(ProjectDir)wwwroot\_framework\"" />
</Target>
wmic process where name='chromedriver.exe' delete