T4 Text Transform template creating xx.cs file avoid ErrorGeneratingOutput - t4

I have a t4 template that is outputting to a specified file name. t4 however when run is creating a xx.cs file for each tt file that I have. Within this file is the text "ErrorGeneratingOutput"
Is there a way to prevent this file from being created?

I'm afraid not, no.
When using one of the mechanisms to create specific files, there will always be a dummy stub file.
Typically I set it to be a text file with
<## output extension=".stub.txt" #>
and put some explanatory text in it to the effect that it's a placeholder by putting that text as the body of the template. I then set its build action to 'None' permanently.
I'm not sure what's causing the error, but that's where any error in the rest of your template would get reported typically.

If you just want to prevent the erroneous generated .cs file from compiling until you are finished writing you t4 file, you can set the Build Action property for the .cs file to None and then set it back when you're done

Related

Better way to include content as-is with AsciiDoc include directive

Context
I am making a script that dynamically inserts include directives in code blocks on an AsciiDoc file and then generates a PDF out of that. A generated AsciiDoc file could look like this:
= Title
[source,java]
---
include::foo.java[]
---
I want the user to be free to include whatever char-based file he or she wants, even other AsciiDoc files.
Problems
My goal is to show the contents as are of these included files. I run into problems when the included file:
is recognized as AsciiDoc beacuse of its extension, an thus any include directives it has are interpreted. I don't want nested includes, just to show the include directive in the code block. Example of undesired behaviour:
contains the code block delimiter ----, as seen on the image above when I end up with two code blocks instead of the intended single one. In this case, it does not matter if the file is recognized as an AsciiDoc file, the problem persists.
My workaround
The script I am writing uses AsciidoctorJ and I am leveraging that I can control how the content of each file is included by using an include processor. Using the include processor I wrap each line of each file with the pass:[] macro. Additionally, I activate macro substitution on the desired code block. A demonstration of this idea is shown in the image above.
Is there a better way to show the exact contents of a file? This works, but it seems like a hack. I would much rather prefer not having to change the read lines as I am currently doing.
EDIT for futher information
I would like to:
not have to escape the block delimiter. I am not exclusively referring to ----, but whatever the delimiter happens to be. For example, the answer by cirrus still has the problem when a line of the included file has .....
not have to escape the include directives in files recognized as AsciiDoc.
In a general note, I don't want to escape (or modify in any way) any lines.
Problem I found with my workaround:
If the last char of a line is a backslash (\), it escapes the closing bracket of the pass:[] macro.
You can try using a literal block. Based on your above example:
a.adoc:
= Title
....
include::c.adoc[]
....
If you use include:: in c.adoc, asciidoctor will still try to find and include the file. As such you will need to replace include:: with \include::
c.adoc:
\include::foo.txt[]
----
----
Which should output the following pdf:

Disallowed types file

It's easy to set the allowed file in code igniter when we want to upload file if the amount is less. But if there are almost extension file I want to set as allowed types of file that can be uploade except file extension of .exe, how the easiest way to set the code ? besides I have to type all of type code in allowed_types configuration. ..

Replacing recorded values with Data file - Data driven testing

I have recorded a simple Coded UI test from visual Studio 2013. What it does is;
Launches a website
Fills in a form with (8 fields)
Saves the form and closes it
Now, I wish to use a data.csv file to replace those 8 values. All the searching I did, I could only find options where every input field had different method hence was easy to find and replace values. In my case, 1 method and 8 fields.
How do I do that? Where do I make the changes since my main file looks like this:
Where and what changes should I make to use CSV file instead of manual values that I recorded.
My designer file code is as below for couple of input fields:
// Type '123456789' in 'i' text box
uIIEdit.Text = this.createKundeParams.UIIEditText;
// Type '{Tab}' in 'i' text box
Keyboard.SendKeys(uIIEdit, this.createKundeParams.UIIEditSendKeys, ModifierKeys.None);
// Type 'Jeff Hardy' in 'name_i' text box
uIName_iEdit.Text = this.createKundeParams.UIName_iEditText;
// Type '{Tab}' in 'name_i' text box
Keyboard.SendKeys(uIName_iEdit, this.createKundeParams.UIName_iEditSendKeys, ModifierKeys.None);
you can put all the 8 values in 1 csv row and treat them as one input to be passed to the method that sets the fields, alternatively you can change the method to accept one value and field name and sets the field with the value
Create the CSV file.
Add the CSV file to the project.
Make sure the CSV file is deployed.
Add the CSV file as a data source for an individual test.
Read the CSV fields and use them in the test.
The detailed steps, with some variations, are explained below.
Visual Studio 2010 has a "data source wizard" that does some of these steps. Visual Studio versions 2012 and 2013 do not have the wizard and so all the steps have to be done manually.
Create the CSV file
One way is to create the file in a spreadsheet then save it as Comma Separated Values. Another way is to use a text editor and just write the file. I use a spreadsheet program for big data source files and a text editor for creating small files. Some editors add a byte order mark (BOM) at the start of a file, that will be added to the first field name of the CSV which appears to make the field unreadable. See this page for more about the BOM.
Add the CSV file to the project
Use the context menu in solution explorer, select Add -> Existing Item. Then browse to the required file. Note the file filter will probably need to be altered to be . or *.csv.
Make sure the CSV file is deployed
Open the properties panel for the CSV file from solution explorer. Set "Copy to output directory" to "Copy if newer" or to "Copy always". Some documents recommend "Copy if newer" but I prefer "Copy always" as occasionally a file was not copied as I expected. The difference between the two copy methods is a little disk space and a little time, but disks are normally big and the time to copy is normally small. Any savings are, in my opinion, far outweighed by being sure that the file will be copied correctly.
Add the CSV file as a data source for an individual test
Replace the [TestMethod] attribute with the correct data source line. This Microsoft blog shows the replacement code for several possible data source file types. For CSV use:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",
"|DataDirectory|\\data.csv", "data#csv",
DataAccessMethod.Sequential), DeploymentItem("data.csv"),
TestMethod]
Note that the file name occurs three times and one copy has a # rather than a .. I have not found any useful documentation about the different fields of the Datasource(...) attribute so cannot advise further on how to choose values for non-CSV data sources.
The |DataDirectory| part above is replaced by the directory where files are deployed when the tests run. The whole file name within the string quotes could be replaced by a full path name of a file, if required.
Read the CSV fields and use them in the test
The Coded UI record and generate tool creates classes with fields that hold values entered into text boxes or used in assertions. Each action method has a ...Params class and each assert method has an ...ExpectedValues class, where the ... is the method name. The default values of these fields are the values used when the test was recorded. The recorded values can be overwritten by an assignment before the action or assertion method is called. The fields of the current row of the data source are accessed from TestContext.DataRow[...].
Suppose a Coded UI test has an EnterValue method that writes text into two fields of the screen and it also has a CheckResult method that asserts one field. The test method might then be written as follows.
[DataSource...
TestMethod]
public void CodedUITestMethod1()
{
this.UIMap.EnterValueParams.UIItem0TextSendKeys = TestContext.DataRow["ValueOne"].ToString();
this.UIMap.EnterValueParams.UIItem1TextSendKeys = TestContext.DataRow["ValueTwo"].ToString();
this.UIMap.EnterValue();
this.UIMap.CheckResultExpectedValues.UIItem0TextDisplayText = TestContext.DataRow["Result"].ToString();
this.UIMap.CheckResult();
}
The ...Params and ...ExpectedValues classes allow the test to create values when the test runs. For example, if the EnterValue method also wanted to write tomorrow's date into a field we could add the following line before it is called:

resource.h is missing

is it possible to generate resource header file if i got the resource.rc file?
You mean, in an automatically manner? If so, check this: Makeheaders.
Otherwise, copy all the function and variable declarations, macros etc. from the resource.c, create a resource.h file and paste them into.

How to specify if a T4 file should produce any output

I am using T4 for generation of some DTO classes + mappers.
I am splitting the files in a number of re-usable bits (some of which containing common methods, some others common procedures) and including them into the T4 templates that will produce my output - which is all good.
My problem is that the re-usable .tt files will try and produce their own output and fail (because they are coupled to some other .tt files) every time I make a change to them, which plain sucks.
I am pretty sure I saw somewhere some directive to specify a given file shouldn't try and produce any output, but I can't seem to track it back.
Any help appreciated!
You can specify invalid extension to suppress the output of your template, for example:
<## output extension="\n" #>
In the properties (select file and press F4) of the T4 files for which you'd like to suppress output, clear the 'Custom Tool' entry.
I don't have enough 'StackOverflow street cred' to reply to Stanislav Kniazev's answer, so will have to post my own here. Thanks for the lead Stanislav Kniazev.
The following worked; but if you are using a T4 syntax highlighter (like Tangible T4) you will find that it stuffs up the highlighting.
<## output extension="\n" #>
So I found setting the extension to something that is not an escape char like this:
<## output extension="" #>
and then in the code section programmatically setting the file extension, like this:
Host.SetFileExtension("\n");
T4 highlighting is then restored.
rename them to .ttinclude and see how that goes for ya....

Resources