I want to be able to copy a single file whose location is static to all folders inside of a specific directory using the copy task in msbuild -- the only thing is that I need that "all folders" part to be dynamic, because I don't know their names up front. I'm able to copy the file to a single directory just fine, and I can even copy to multiple directories when I specify the destination folder paths by name, but i want to be able to copy to however many folders exist in a given directory, even if those folder are empty (that's another issue I can't seem to get by). How do i copy one file (known location) to X number of folders (names not known) inside of a directory using the msbuild copy task?
First list the directories to copy to, then copy the file to each of them using item batching.
<!--declare the source file and target directories somewhere-->
<PropertyGroup>
<MyTargetDir>c:\temp</MyTargetDir>
<MySourceFile>c:\somefile</MySourceFile>
</PropertyGroup>
<Target Name="CopyToSubDirs">
<!--list dirs-->
<ItemGroup>
<TargetDirs Include="$([System.IO.Directory]::GetDirectories(`$(MyTargetDir)`))"/>
</ItemGroup>
<!--copy to each dir-->
<Copy SourceFiles="$(MySourceFile)" DestinationFolder="%(TargetDirs.Identity)"/>
</Target>
Related
In THREDDS server setup, I need to configure datasetScan filter element in catalog.xml so that it takes into account full file path, not just file name or directory name. Say, I have following folder structure:
/GGG/alpha/a
/b
/c
/GGG/beta/a
/b
/c
And I want to remove a file named a only from folder alpha. I can remove the file a from both folders by setting
<exclude wildcard="a"/>
or I can remove the folder alpha completely by setting
<exclude wildcard="alpha" atomic="false" collection="true"/>
but setting wildcard="alpha/a" or anything similar does not seem to work. I have also tried regexp instead of wildcard and different combinations of atomic and collection, but no luck. Is my understanding correct that it is not currently possible to filter by folder and file names in one rule?
The <exclude> and <include> elements only allows to match the name, but no the full path.
P.S.: BTW, I have just made a pull request at the Thredds' GitHub repository to include this funcionality.
https://github.com/Unidata/thredds/pull/1015
Probably some tests and improvement should be reviewed.
I want to create a model jar file but not include the source code. Is it possible? The Repast model installer includes the source code by default, but I would like to hide it from the recipient of the model.
Yes, it’s possible but there is an important caveat. Compiled Java code distributed as binary files like jars can be trivially de-compiled back into the original source code with remarkable accuracy. If your goal is to protect proprietary source code then code obfuscation is required – see https://www.excelsior-usa.com/articles/java-obfuscators.html for more details. Code obfuscation is unfortunately a fairly complicated subject.
There are two ways to omit the project source code from the Repast model installer:
Method 1 – Remove /src elements from the model installer configuration files. This will instruct the model installer to omit /src files in the installer jar. The compiled agent classes will be in the usual project /bin folder.
In the /installer/installation_compnents.xml file, around line 156 comment the following:
<!--
<pack name="Sources" required="no">
<description>The model source code</description>
<file src="$StagingOptionalArea/src" targetdir="$INSTALL_PATH/Geography"/>
</pack>
-->
The “” denote the start and end of the code block that is commented. Next, in the /installer/installation_coordinator.xml file, comment around line 62:
<!-- Copy optional files to a separate directory -->
<copy todir="${StagingOptionalArea}" overwrite="true" failonerror="false">
<fileset dir="." casesensitive="no">
<!-- <include name="**/src/**" /> -->
<include name="**/docs/**" />
</fileset>
</copy>
Here you only want to comment the single line that copies the /src folder and not the /docs folder (although you can if you like). Now just build the model installer as usual.
Method 2 – export the /src folder to a jar file. This method does not require any changes to the default installer files as in the first method. However it requires deleting the source code after exporting it to a JAR file which means you would need to work on a copy of the project to preserve your source code. To export the model code to a JAR file, right click on the /src folder and select Export… -> Java -> JAR file. In the export dialog, make sure the src folder is checked in the “Select resources to export” box and then specify the JAR file name and location. The best place to export the jar file in in the project /lib folder. Most other options should be left as default. Make sure that “Export Java source files and resources” is unchecked, otherwise it will copy the source into the jar file. After the JAR files is generated and you verify that it exists in the /lib folder, then delete the contents of the /src folder but not the /src folder itself. This will permanently delete the model source code, so again please work on a copy of the project if you take this route. Simply renaming or deleting the /src folder will cause the installer to fail, so the delete is required for this method. Last, the user_path.xml file in the .rs folder needs to be updated to reflect the change in the source code location. Change the line to assuming that the exported model JAR file is in the /lib folder. All of the model code is now in the single JAR file in your project/lib folder. The /src and /bin folder should be empty at this point. build the model installer as usual. The option to install source code will still appear in the installer, but no source is contained in the installer JAR so no source will be copied upon installation.
I am writing a MSBuild script for creating a one click deployment. Everything works great but the files are created in the app.publish under the bin directory. Is there a way to set the output directory to another directory instead of the default bin directory?
I used PublishDir but that just creates the setup.exe in the specified directory. The other files are still created under the bin directory.
Can route all the one click deployments to a specific directory or do I have to copy later?
Thanks,
Richard.
Have you tried OutputPath instead?
msbuild my_solution.sln /p:OutputPath=c:\my_dir
It seems that MsBuild creates a folder called, "BuildType" on the build server and this folder is where the .proj file is copied. In source control I have several files that are in the same folder as the build project file. I have a workspace mapped to this location.
I would like to be able to specify explicitly which files from this workspace location should be copied to the build machine. Is this possible?
Thanks!
You cannot do this on file level but if you organize your build type folder with subfolders you can cloak the folders that you want to exclude.
I'm trying to move all files of a certain type to a directory relative to the file itself and I'm wondering if it's possible using MSBuild.
Basically, I'm using the Microsoft AJAX Minifier to minify all Javascript and CSS files on my site. This outputs .min.js and .min.css files into the same directory as the Javascript and CSS files. Because my site has numerous skins, there are JS and CSS files located in numerous directories. I want to be able to add a task that runs after the AJAX Minifier that moves all .min.js and .min.css files to /min/ relative to the file location. So /Skin1/somescript.min.js would move to /Skin1/min/somescript.min.js and /Skin2/somescript.min.js would move to /Skin2/somescript.min.js.
The only way I know to accomplish a copy/move requires knowledge of the absolute directory (or should I say directory relative to the Project file) but I can't seem to find a way to move based on a directory relative to the file I'm moving.
Can this be done?
<CreateItem Include="wwwroot\**\*.min.js;wwwroot\**\*.min.css">
<Output TaskParameter="Include" ItemName="FilesToMove" />
</CreateItem>
<Move SourceFiles="#(FilesToMove)" DestinationFiles="#(FilesToMove->'wwwroot\%(RecursiveDir)\min\%(Filename)%(Extension)')"/>
Assuming you're using the Move task from MSBuild community tasks. If not, you could just copy and then delete the originals instead.