How do I handle multiple App.config files in my WIX Project? - batch-file

I'm trying to figure out a way to handle multiple app.config files. Each app.config file is for a different enviornment.
Currently, I have multiple .SED Files(each .SED file references to one enviornment) that in their post-command(PostInstallCmd) they execute a .bat file that looks for a certain app.config and puts in the directory needed. However, the problem with this method is that the command prompt opens up after the installation and I am unable to figure out how to suppress the command prompt.
I am not sure if my way is the best idea to go about handling multiple App.Config. That is why I am throwing it out there to see if there is a better method or if someone has a solution to the method I already have.

If you keep your config files in separate components, you can add a condition element to your components.
Component conditions are evaluated during the CostFinalize standard action (source), so you'd have to use a custom action that runs before file costing to gather info about the environment. You can use the built-in OSInfo custom actions or predefined properties to do so.
Just set the File/#Name attribute to the same across all the config files if they have different names on your build server. Unfortunately, this will set off ICE30, but if the conditions are mutually exclusive, you can safely ignore it.
Your xml would look something like:
<Component Guid="PUT-GUID-HERE">
<Condition>VersionNT = 602</Condition>
<File Name="app.config" Source="config1.config" />
</Component>
<Component Guid="PUT-GUID-HERE">
<Condition>NOT VersionNT = 602</Condition>
<File Name="app.config" Source="config2.config" />
</Component>
Note that you'll have to specify component guids, because they have the same target path. The auto generated guid would be the same for both.

Related

Is it possible to edit Logic app file system or SFTP trigger conditions to fire a logic app based on filename or extension?

I would like to trigger my logic app which is reading files from SFTP only if files with a certain name or extension are uploaded/modified. I want to avoid using multiple actions to check file name. Is there any possible way to edit File System/SFTP trigger conditions to check file name and accordingly trigger the logic app?
Yes you could. If you want to use trigger condition to check the file name, you have to use When a file is added or modified (properties only).
I test the one without properties only, I check the output is there any property to get the file name, and then I use #equals('47.txt',trigger()['outputs']['headers']['x-ms-file-name']) as trigger condition, however I get this error message.
So this trigger could not meet your requirement. Then I test with properties only, this output body has a property Displayname to get the file name. So I changed the codition to #equals('47.txt',trigger()['outputs']['body']['DisplayName']), with this codition, if the filename doesn't equal, it will be triggered, however it won't fired it.
Hope this could help you.

PHPMD and PHPCS Camelcase for Tests

I just installed both PHPMD and PHPCS with my Project.
Now, I would like to customize them a bit, but can't seem to achieve it.
I get 2 warnings that I would like to remove for all my project:
phpcs: public method name MyTests::my_test_that_should_pass is not in camel caps format
phpmd: the method my_test_that_should_pass is not in camel case
With PHPMD, I tried to change : .composer/vendor/phpmd/phpmd/src/main/resources/rulesets/controversial.xml and set allow-underscore-test to true like mentioned here
With PHPCS, I don't really know how to do it.
Any idea???
https://phpmd.org/rules/controversial.html
PHPCS uses a file called ruleset.xml to allow you to create your own custom standard. The documentation for it is here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
If you want a specific standard for your project, you can include a phpcs.xml file at the root of your project. It's exactly the same format as a ruleset.xml file and can even specify which files and folders need checking by default. Documentation for that is here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file
I have no idea what coding standard you are using with PHPCS right now, but I'll assume you are using PSR2.
If you run phpcs with the -s option, you'll see an error message with an error code, like this: Method name "MyTests::my_test_that_should_pass" is not in camel caps format (PSR1.Methods.CamelCapsMethodName.NotCamelCaps). The code is the bit you need here.
For your custom standard, you want PSR2, but you don't want the PSR1.Methods.CamelCapsMethodName sniff because you obviously don't want PHPCS checking for camel case. So create a ruleset with this content:
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>My custom coding standard.</description>
<rule ref="PSR2">
<exclude name="PSR1.Methods.CamelCapsMethodName"/>
</rule>
</ruleset>
Save that file and call it ruleset.xml or phpcs.xml and then run PHPCS using it: phpcs /path/to/code --standard=/path/to/ruleset.xml
Take a look at the annotated ruleset docs I linked at the top of the comment because there is a lot more you can do with those rulesets.

can we drop a file to a folder location automatically using camel,or at a set period of time(not intervals)?

Iam trying to automate the testing of a java bundle,Which will process once a file is dropped in a particular folder.
can we drop a file to a folder location automatically using camel,or at a set period of time(not intervals)?
is this possible purely by camel or should we incorporate other frameworks?
sure, you can use the camel-file component to produce (create files somewhere) and consume (read/process files from somewhere) and optionally control the initial/polling delays easily with attributes...
here is a simple example of consuming->processing->producing
from("file://inputdir").process(<dosomething>).to("file://outputdir")
alternatively, you could periodically produce a file and drop it somewhere
from("timer://foo?fixedRate=true&period=60000").process(<createFileContent>").to("file://inputdir");
Although camel could do this by creating a timer endpoint, then setting the file content and writing to a file endpoint, my answer would be to simply use a bash script. No camel needed here.
Pseudo bash script:
while [ true ]
do
cp filefrom fileto
pauze 10s
done

Reading properties in properties file with ant not respects order

Reading properties in properties file with ant not respects order.
The order is not respected:
Example:
<property file="build.properties" prefix="prefix."/>
<propertyselector property="cases" match="prefix.project\.(.*)" select="\1"/>
<for list="${cases}" param="pr">
<sequential>
<echo message="Project: #{pr} Version: ${prefix.project.#{pr}}"/>
</sequential>
</for>
with:
build.properties
project.1 = 1.2.3
project.8 = 5.9.4
project.4 = 3.5.0
Get:
Project: 8 Version 5.9.4
Project: 1 Version 1.2.3
Project: 4 Version 3.5.0
(And the result seems to randomly change)
I have to build them in the order like they appear in the build.properties file ??
The property file is being read in the correct order. You can test this by simply putting in duplicate properties and see which one gets defined. Here's build.properties:
dup.prop = foo
dup.prop = bar
And here's my Ant script:
<project>
<property file="build.properties"/>
<echo>Dup.prop is set to "${dup.prop}".</echo>
</project>
Running this, I'll get:
Dup.prop is set to "foo".
That's because the value foo is defined first in build.properies, and once a property is defined, it cannot be (easily) changed.
What you're trying to do is to access the properties in the order they're defined. That isn't guaranteed because properties are stored in a hash.
You mention sub-projects, and those sub-projects must be built in a particular order. Unfortunately, it's hard to tell exactly what could be the issue since you didn't give us an outline of your actual issue and some sample build scripts for projects and sub-projects.
First, Ant is a build matrix language which means it has a dependency hierarchy. The biggest issue developers have is attempting to force build matrix languages to execute in a particular order. You should specify a dependency hierarchy in your build.xml files (and the fewer there are, the easier it is for Ant to get things right).
If sub-project "B" depends upon a jar file in sub-project "A", It should be in sub-project "B"'s Ant script a dependency on sub-project "A" jar build.
<project name="proj-b"/>
...
<target name="build-jar"
depends="test.if.jar.exists"
unless="jar.exist">
<ant directory="${proj.a.dir}"
target="build.depend.jar"/>
</target>
<target name="test.if.jar.exists">
<condition property="jar.exists">
<available file="${proj.a.dir}/dist/${dend.jar.file}"/>
</condition>
</target>
<target name="compile"
depends="build-jar">
....
</target>
...
</project>
In the above build.xml for Project "B", I depend upon some jar file that Project "A" builds before I can compile Project "B". Therefore, my compile task depends upon build-jar which will build Target "A"'s jar file. To prevent this task from building Project "A"'s jar over and over, I use <condition> as a test to see if this jar exists. If it already does, I don't rebuild the jar.
In this case:
Target "compile" is called. That target realizes it depends upon Target "build-jar".
Before Target "compile" is executed. Target "build-jar" is first called.
Target "build-jar" depends upon Target "test.if.jar.exists".
Before "build-jar" is executed, it calls Target "test.if.jar.exists"
In Target "test.if.jar.exists", if the jar already exists, the property jar.exists will be set.
Now, Target "build-jar" is active, and looks to see if the property jar.exists is set. If it is, the target won't execute.
Finally, control returns to Target "compile" which then executes.
Here I'm not enforcing order directly. Instead, I merely have a dependency hierarchy that I specify, and I let Ant figure out exactly what to do.
If dependent jar issues are a big issue, you can also look into Ivy. Ivy allows you to create a Jar Repository. Your projects that build jars the rest of your projects are dependent upon can fetch the needed jars from this repository. This is very similar to Maven. In fact, Ant with Ivy can use Maven repositories. We use Artifactory, a local Maven repository manager, for our Ant projects.
You can also try the <subant> task which does allow you to specify a buildpath which would allow you to say build sub-project "A" before sub-project "B". You can define the buildpath in another Ant XML file which could be dependent upon customer and then use <import> to import the build path for that project.
Indeed. Java properties are represented with a java.util.Hashtable, and as you surely know, hash tables do not preserve order. You simply cannot do what you want with a properties file.
If those "projects" that you state you want to build in order are in turn Ant projects, you may want to consider moving their tasks to your main build-file instead, and simply enforce the proper building order using normal Ant dependencies.
The below code will help to sort the list generated by propertyselector tag
<sortlist property="my.sorted.list" value="${my.list}"
delimiter="," />
<echo message="${my.sorted.list}" />

Avoid hardcoded icon file paths in .resx file

I'm trying to get our app to handle different icon sets (make it sort of skinnable). I asked about the usual way to do it here. When I tried to apply the solution from the answer, I replaced all hardcoded icon paths in .resx files with paths using an environment variable. For example, I replaced...
<data name="btnDel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\Icons\btnDel.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
...with:
<data name="btnDel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>$(IconsFolder)\btnDel.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Then, as an initial test, I defined a System-level environment variable called IconsFolder, applied changes, restarted Visual Studio and tried to build. But I got this error:
D:\SVN.DRA.WorkingCopy\UserControl\My Project\Resources.resx(123,5): error MSB3103: Invalid Resx file. Could not find a part of the path 'D:\SVN.DRA.WorkingCopy\UserControl\My Project\$(IconsFolder)\btnDel.png'. Line 123, position 5.
It seems like .resx files don't understand environment variables. How can I avoid hardcoding those paths, then?
EDIT: Each icon can be referenced by more than one project, so the environment variable of whatever mechanism is used to configure the paths must be available on a solution-wide basis, and I should be able to set it from inside an MSBuild script.
EDIT 2: All my forms are defined in C# or VB.NET projects
System wide environment variables may not work. You might want to try following the instructions here:
http://msdn.microsoft.com/en-us/library/ms173406.aspx
I don't think there is a way to accomplish using the resource file. One way to achieve this is to drop your bitmap on your project, right click it and change build action to "Embedded Resource". Open up the project file in text editor and change the path to your environment variable. (this is how we do it with VS 2008, they have made it easier since then). Then in code you can do this....
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream("btnDel.png");
new System.Drawing.Bitmap(myStream);

Resources