Applying .tt on build using T4ToolBox - build

I have got some .tt files in my solution for a long time.
I recently decided to launch the transformation at build time by adding to my csproj :
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>
I have a first .tt file (First.tt) which includes a second .tt file (Second.tt) from another project of the same solution:
<## include file="..\SecondProject\Second.tt" #>
In Second.tt, I include T4Toolbox.tt :
<## include file="T4Toolbox.tt" #>
Everything is ok when I launch First.tt by using right click -> run custom tool.
But when I rebuild the solution, I obtain this error :
Failed to resolve include text for file:E:\Dev\MySolution\FirstProject..\SecondProject\T4Toolbox.tt
So I try to use the installation path of T4ToolBox.tt :
<## include file="C:\Program Files\T4 Toolbox\T4Toolbox.tt" #>
But I have got another error : A processor named 'T4Toolbox.DteProcessor' could not be found for the directive named 'dte'
If anybody can help, it would be great !
EDIT : I have not succeeded but it is better. I removed the rooted path in Second.tt and I have added the following lines into the csproj of FirstProject :
<PropertyGroup>
<IncludeFolders>C:\Program Files\T4 Toolbox</IncludeFolders>
</PropertyGroup>
<DirectiveProcessor Include="T4Toolbox.DteProcessor" >
<Class>T4Toolbox.DteProcessor</Class>
<CodeBase>C:\Program Files\T4 Toolbox\Bin\T4Toolbox.10.0.dll</CodeBase>
</DirectiveProcessor>
<DirectiveProcessor Include="T4Toolbox.TransformationContextProcessor" >
<Class>T4Toolbox.TransformationContextProcessor</Class>
<CodeBase>C:\Program Files\T4 Toolbox\Bin\T4Toolbox.10.0.dll</CodeBase>
</DirectiveProcessor>
When I try to build, the dte processor is found but I have still an error :
An Exception was thrown while running the transformation code. The process cannot continue. The following Exception was thrown:
System.NullReferenceException: Object reference not set to an instance of an object.
at T4Toolbox.DteProcessor.UpdateFiles(ICollection`1 outputFiles)
at T4Toolbox.OutputManager.UpdateFiles()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at T4Toolbox.TransformationContext.OnTransformationEnded(TextTransformation transformation)
at Microsoft.VisualStudio.TextTemplating7C4960D0E15B020F44790E9542C211BF.GeneratedTextTransformation.Dispose(Boolean disposing) in E:\Dev\MySolution\FirstProject\First.tt:line 18
at Microsoft.VisualStudio.TextTemplating.TextTransformation.Dispose()
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result). Line=0, Column=0 E:\Dev\Tools\Microsoft\Microsoft.TextTemplating.targets 397 5 FirstProject

Related

Using custom script files with C++ project in Visual Studio 2019

TL;DR
My project uses a custom script file at runtime.
My project builds fine in VS and runs on the command line.
However when running in VS an error is thrown implying the file doesn't exist.
Full Details
My c++ project uses a custom scripting file to apply some settings at run time:
these are javascript like but not actual javascript
having these settings not in compiled files means they may be changed without recompiling
Everything builds fine, the script is copied using xcopy in a post build event.
When running in VS2019 it doesn't seem to be able to find the scripting file.
An opaque, library specific error is issued: A GenApi error has occurred
But when running the resulting .exe from cmd everything works, the script is used no problem.
If the script file is removed from the output dir and the .exe is run again I get the same A GenApi error has occurred.
I have tried:
running in release and debug.
including and excluding the file from the build.
I don't want to debug the script, I just need it to be used during start up so I can debug the rest of the program which is in C++.....
Example Code
Main.cpp
#include <iostream>
#include <EGrabber.h>
void configure() {
Euresys::EGenTL gentl;
Euresys::EGrabber<> grabber(gentl);
grabber.runScript("config.js");
}
int main() {
try {
configure();
} catch (const std::exception &e) {
std::cout << "error: " << e.what() << std::endl;
}
}
config.js
var grabber = grabbers[0];
var FPS = 150;
// camera configuration
grabber.RemotePort.set("TriggerMode", "On");
grabber.RemotePort.set("TriggerSource", "CXPin");
grabber.RemotePort.set("ExposureMode", "TriggerWidth");
// frame grabber configuration
grabber.DevicePort.set("CameraControlMethod", "RG");
grabber.DevicePort.set("CycleTriggerSource", "Immediate");
grabber.DevicePort.set("CycleMinimumPeriod", 1e6 / FPS);
More info:
script documentation
based on #john 's comment:
There is a different current working directory when running from VS and when running from the command line.
When run from VS the current working directory is the project directory not the output directory.
The script was in project-dir\src not the immediate project dir.
Moving the script up to the project directory solved everything.
Alternative solutions, which worked:
Use the full path: C:\\full\\path\\config.js
(the application startup path can be extracted from argv[0])
Change the debug working directory in VS:
Project -> Properties -> Configuration Properties -> Debugging -> Working Directory
Enter output path, eg: $(SolutionDir)bin$(Platform)$(Configuration)\

Install vcredist_x64 with VS2017 installer project

I currently want to create a installer for a VS2017 project. This project has as prerequisite vcredist_x64.
To create an installer I have installed:
- ClickOnce Publishing (via VS2017 installer)
- Microsoft Visual Studio 2017 Installer Projects (VS2017 Addon by Microsoft)
Now I created a setup project and in properties => prerequisite I selected Visual C++ "14" Runtime Libraries (x64) and Download prerequisites from the component vendor's web site.
If I now start created setup.exe I'm getting on my target machine an error during installing of prerequisites: The following packages could not be found: (there is not a single packages listed).
Log file:
The following properties have been set:
Property: [AdminUser] = true {boolean}
Property: [InstallMode] = HomeSite {string}
Property: [NTProductType] = 1 {int}
Property: [ProcessorArchitecture] = AMD64 {string}
Property: [VersionNT] = 10.0.0 {version}
Running checks for package 'Visual C++ "14" Runtime Libraries (x64)', phase BuildList
Running MsiProductCheck with ProductCode '{C99E2ADC-0347-336E-A603-F1992B09D582}'
MsiQueryProductState returned '-1'
Setting value '-1 {int}' for property 'VCRedistInstalled'
The following properties have been set for package 'Visual C++ "14" Runtime Libraries (x64)':
Property: [VCRedistInstalled] = -1 {int}
Running checks for command 'vc_redist.x64.exe'
Result of running operator 'ValueGreaterThanEqualTo' on property 'VCRedistInstalled' and value '3': false
Result of running operator 'ValueEqualTo' on property 'AdminUser' and value 'false': false
Result of running operator 'ValueNotEqualTo' on property 'ProcessorArchitecture' and value 'AMD64': false
Result of running operator 'VersionLessThan' on property 'VersionNT' and value '6.00': false
Result of checks for command 'vc_redist.x64.exe' is 'Install'
'Visual C++ "14" Runtime Libraries (x64)' RunCheck result: Install Needed
Installation of components 'Visual C++ "14" Runtime Libraries (x64)' was accepted.
Copying files to temporary directory "C:\Users\blubb_user\AppData\Local\Temp\VSD1A14.tmp\"
Error: The following package files could not be found:
In VS 2015 I had same trouble. Fix there was to fix PublicKey in bootstrapp file. But I was not able to find correct PublicKey. I was trying using the PublicKey of signature of matching installer. In C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\vcredist_x64\product.xml GUID C99E2ADC-0347-336E-A603-F1992B09D582 is mentioned, so I looked for setup with this GUID in C:\ProgramData\Package Cache\ and took this PublicKey.
Any idea how to fix it for VS2017?
Update (Solution):
I was able to fix it for me (VS2017 Update 7):
In packages.xml (C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\vcredist_x64\en) path of VCRedistExe was invalid.
Instead of
<String Name="VCRedistExe">https://aka.ms/vs/15/release/26405.00/VC_Redist.x64.exe</String>
I have now
<String Name="VCRedistExe">https://aka.ms/vs/15/release/26429.04/VC_Redist.x64.exe</String>
C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\vcredist_x64\product.xml I changed too
<Product xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" ProductCode="Microsoft.Visual.C++.14.0.x64">
<!-- Defines list of files to be copied on build -->
<PackageFiles CopyAllPackageFiles="false">
<PackageFile Name="vc_redist.x64.exe" HomeSite="VCRedistExe" PublicKey="3082010a0282010100a829fed410c8ff550a9e990003528fdcb0bff9abf851fe5c8c54c227ce4c2b96ebdb811ccb862b79ca757eb867832686bdd62f1c3ec758aa8f6f95fb5afca7c61bc1c3e84c174e223db75b565c7fd75af52dbabba609bf067cee98fe40f930b86bfe406f74b3b8d63849c9d087072f31dfb6bc4ea3d09eb7627b5670754f67bf05cca3aebe0092c21b50a1613b100001b186d029f340f50fd9a30f57ab6309a8dca96ae74743a7be15c43d27a4e8565288cf5999a10084369bd039d22a0d2fe604e2bf13968883a95137184189e2f9859d8e651a3d0364ccc5de50705df20b85a98fb145e877ff839d09bb72e0e6560895b92b83128931fce758721dbdf983230203010001" />
</PackageFiles>
<InstallChecks>
<MsiProductCheck Property="VCRedistInstalled" Product="{03EBF679-E886-38AD-8E70-28658449F7F9}"/>
</InstallChecks>
<!-- Defines how to invoke the setup for the Visual C++ 14.0 redist -->
<Commands Reboot="Defer">
<Command PackageFile="vc_redist.x64.exe" Arguments=' /q '>
<!-- These checks determine whether the package is to be installed -->
<InstallConditions>
<BypassIf Property="VCRedistInstalled" Compare="ValueGreaterThanOrEqualTo" Value="3"/>
<!-- Block install if user does not have admin privileges -->
<FailIf Property="AdminUser" Compare="ValueEqualTo" Value="false" String="AdminRequired"/>
<!-- Block install on any platform other than x64 -->
<FailIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="AMD64" String="InvalidOS"/>
<!-- Block install on Vista or below -->
<FailIf Property="VersionNT" Compare="VersionLessThan" Value="6.00" String="InvalidPlatformWinNT"/>
</InstallConditions>
<ExitCodes>
<ExitCode Value="0" Result="Success"/>
<ExitCode Value="3010" Result="SuccessReboot"/>
<DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
</ExitCodes>
</Command>
</Commands>
</Product>
I'm not sure about Product="{03EBF679-E886-38AD-8E70-28658449F7F9}", because Setup has GUID {80586c77-db42-44bb-bfc8-7aebbb220c00} (MsiProductCheck does not work with it), so I took GUID from Microsoft Visual C++ 2017 x64 Minimum Runtime - 14.14.26429. Another possibility is to use GUID from Microsoft Visual C++ 2017 x64 Additional Runtime - 14.14.26429 ({B12F584A-DE7A-3EE3-8EC4-8A64DBC0F2A7}). Minimum and Additional Runtime will be installed with script above, so it should doesn't matter which GUID we take.
I had this problem with the x86 redist and was eventually able to blame everything on the MS supplied vcredist_x86\product.xml file. You should be able to apply the same fix to the vcredist_x64\product.xml file.
The problem arises due to file name and public key mismatches with the actual redist file that you download from MS.
You must change the name in both the PackageFiles\PackageFile node and Commands\Command node of product.xml to vcredist_x64.exe, as well as renaming the redist package from MS to vcredist_x64.exe. Then, change the publickey attribute in the PackageFile node to match the public key of the EXE you got from MS. You can get this by looking at the EXE's SHA1 certificate with File Explorer (Properties -> Digital Signatures (SHA1) -> Details -> View Certificate -> Details -> Public Key)
Same problem. Microsoft had a typo in their bootstrapper file. In C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages\vcredist_x86\product.xml
replace vcredist_x86.exe with vc_redist.x86.exe and reload Visual Studio.
For vs2015,vs2017,vs2019: I had to right-click select Properties on the VC_redist.x86.exe file, then select Digital Signatures tab, select sha256 (not sha1) as above, then Details button to get the Certificate properties window, then the Details tab on that. Then I had to scroll down to Public Key. From there I had to select and Ctrl+C copy the hexadecimal Public key text from the ASCII dump window below since the Copy to File button only creates .cer files. Then I had to edit the product.xml file in Notepad++ launched in Administrator mode or else you won't be able to save the updated file. After pasting the Public key text into the product.xml file, I had to select the lines of the key and replace all the spaces separating the hex digits with "". Then I replaced the PublicKey value and finally saved.
Does anyone else think it odd that in 2020 the vc_redist.*.exe file still has no versioning reflected in the name, that the download site doesn't indicate the version in the text, does not indicate the public key, and that therefore the only way to know it's been updated since you last downloaded it is to compare the file size with your last version?
Update 2020-11-04: After downloading the latest redist from https://support.microsoft.com/en-ca/help/2977003/the-latest-supported-visual-c-downloads and updating product.xml as above, when installing my application with the updated msi, I get an error indicating "The following package files could not be found: vc_runtimeMinimum_x64.msi". In comparing the vc_redist exe I downloaded today to the one I had been using, I noted it is smaller. Looks like I get to go back to an older version.

Nugetserver onpremise unable to run due to newtonsoft.json version

Target set as .net 4.6 in a vs2015 environment. All fetch and built no errors.
Used https://www.hanselman.com/blog/HowToHostYourOwnNuGetServerAndPackageFeed.aspx and MS doco as reference.
When run under IIS, shows error below
How do I resolve this ?
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
NB: Version on the Newtonsoft.Json.dll file is 9.0.1.19813
web.config has these 2 lines, do I need to make this and nugget.dll.config have newVersion="9.0.2.0" say ?
< assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
< bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.1.0" />
I have it working, what I did was change the default project of "nuget" to "nugetwebserver" and adjusted the assemblies and module name.
Then did a fresh compile. I suspect the poor choice of name caused some conflict with the some setting seeing by nuget.server project was called ..
Interestingly the http://server/nugetserver2.7/nuget would render in IE
http://server/nugetserver3.1/nuget asks me if I want to download the content. The content being the same as the rendered page for 2.7..

gdbinit "no such file or directory" Eclipse c

I'm using Xming to connect to a Linux (enterprise edition) server on which I'm trying to debug a C++ project in Eclipse Galileo. The following errors occurred:
Reading symbols from ../workspace/myfile ..(no debugging symbols found) ... done.
.gdbinit : No such file or directory
Setting environment variable "LS_COLORS " to null value
(.gdbinit is on the server (in root), my account has rights)
If i try to run gmake on the same file from the terminal I get the following error :
gmake ** No rule to make target /workspace/myfile' . Stop.
//I have exported the path (including the library path), and gmake exists.
My project has 3 subprojects (proj1 , proj2 and proj 3). In order to debug proj3 I have to build projs 1 and 2 . I created make targets for projects 1 and 2, and I obtained .so files for which i made softlinks to corresponding files in my_project/libs folder.
My Eclipse debug configuration is as follows (tab order):
Main
  Project: My Project
  Build Configuration: UseActive
  C++ Application: path to my project/myproject
  Environment: path to libs on server (my user rights)
Debugger
  Debugger: gdb/mi
  (Checked) Stop startup at main
  GDB debugger: gdb
  GDB command line .gdbinit
  GDB command set: standard
  Protocol mi
Project Properties:
  Builders CDT Builder
  Scanner Configuration Builder
  C/C++ Build
  Build command gmake -k
Behaviour
  build incremental build : all ( sometimes i get the error no rule for make all)
  Clean: clean
  Discovery options:
    (Checked) Automatic discovery path
    (checked) Report path detection problems
    Discovery profile GCC per project
    (checked ) Enable build output
    Compile invocation comand gcc
    Toolchain
    No toolchain
    Correct builder GNU make builder
This Eclipse debug configuration works on another account (on the same server using the same Eclipse). The gdbinit and gmake files are on the server and work, I'm not supposed to update the versions (this was one solution I found online).
Has anyone seen this error before? Does anyone have a clue what I'm doing wrong?

Problem while building a .dll (Visual C++)

I am trying to build a .dll in order to link it to one of my projects. But the build always fails : I got these messages in the output and I don't know what it means. It seems that something is missing, but I couldn't find what.
I am trying to link a Mesher called Netgen
http://www.hpfem.jku.at/netgen/
1>adfront2.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1> Creating library D:\Documents\Visual Studio 2008\Projects\converter/lib\nglib.lib and object D:\Documents\Visual Studio 2008\Projects\converter/lib\nglib.exp
1>Embedding manifest...
1>Performing Post-Build Event...
1>Environment variable NETGENDIR not found.... using default location!!!
1>POSTBUILD Script for nglib ........
1>Installing required files into XXX\Netgen\windows....\nglib-instNoOCC_Win32 ....
1>File not found - nglib.dll
1>0 File(s) copied
1>POSTBUILD Script for nglib FAILED..... Error copying the nglib DLL into install folder!!!
1>Project : error PRJ0002 : Error result 1 returned from 'C:\Windows\SysWow64\cmd.exe'.
1>Build log was saved at "file://D:\Documents\Visual Studio 2008\Projects\converter\BuildLog_nglib.htm"
1>nglib - 1 error(s), 49 warning(s)
I hope I am clear enough and thank you by advance for your help.
seems this NetGen lib's project wants to run a post-build event in which it tries to copy the main output (the nglib.dll) to the directory NETGENDIR (which is supposed to be an environment variable). This fails beccuse the dll isn't found.
Either disable the post build event, or check with the NetGen lib's creator what they expect here, there seems to be a mismatch between the project's output dir and the postbuild event.
Would also be nice to see the postbuild event from the vcproj file, maybe you can post it?
You need read, by example the output line:
1>Environment variable NETGENDIR not found.... using default location!!!
After that I suggest that you must read the documentation about how define a enviroment variable named: NETGENDIR