Build openssl from source wtih link option “Integrity Check” in Visual Studio - c#

I want to add "IntegrityCheck" as a command line parameter to the linker when i build openssl 1.1.0 from source. How can i do it?
Thank a lot

If you read the "INSTALL" text file that comes with the source you can find this option:
VAR=value
Assignment of environment variable for Configure. These
work just like normal environment variable assignments,
but are supported on all platforms and are confined to
the configuration scripts only. These assignments override
the corresponding value in the inherited environment, if
there is one.
The following variables are used as "make variables" and
can be used as an alternative to giving preprocessor,
compiler and linker options directly as configuration.
The following variables are supported:
LDFLAGS Flags for the shared library, DSO and
program linker.
So for windows you would need to run the configure script something like:
perl Configure VC-WIN32 LDFLAGS="/INTEGRITYCHECK"
(I'm not sure on the exact syntax of the switch to pass through, so may need to drop the '/')
then run the normal nmake to build it.

Related

How to get VSTest to use ServerGC without changing the app.config (.NET framework)?

I have a .NET 4.7.1 C# class library with some associated tests in a separate project.
I would like to be able to run the tests in ServerGC mode to replicate the standard usage of the class library by consumers (both for normal and performance-related tests).
As per Microsoft documentation here it is possible to configure ServerGC in a number of ways.
The runtimeconfig.json isn't an option because this is a .NET Framework project.
After some playing around with regular projects and tests projects. It appears to be the case that ServerGC must be set for whatever the parent process is for it to take effect. In the case of a regular application this is fine and makes it trivial to use the MSBuild property ServerGarbageCollection or the app.config file. In the case of running a project via VSTest, this makes the test runner (vstest.console.exe) the parent process which therefore means that the ServerGarbageCollection property has no effect. I would prefer not to have to change the app.config for vstest.console.exe because it is used by all test runs on that machine and could therefore interfere with other solutions.
The Microsoft documentation suggests that it is possible to set the environment variable: COMPlus_gcServer with a value of 1 to enable ServerGC. It is possible to set environment variables for VSTest in the runsettings file as shown by the example below and at the bottom of the documentation here. The documentation also states that specifying an environment variable will enforce the /InIsolation flag to ensure that the environment variables are set and then the test run process is started. However this doesn't appear to work.
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<COMPlus_gcServer>1</COMPlus_gcServer>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
I have added a simple test case which checks the GCSettings.IsServerGC property and still gives false despite the environment variable being successfully read as having a value of 1 within the same test.
Edit: Having done more reading, it looks like the runtimeconfig.json property, the MSBuild property and the Environment variable are all .NETCore only. This leaves the only option as somehow providing VSTest with an app.config that contains the GCServer property. Is there any way to do this via runsettings or command line arguments to VSTest?

Is there a way to skip /AI switch, when we add dependency of C# library to C++ target?

I'm setting up some Visual Studio Solution, where I have some C# and C++ projects. I wonder if I can somehow simplify the CMake code which manages the dependency between the C++ target and the C# library.
It should work on Visual Studio 2015 with CMake 3.15. On this page I read that the target_link_libraries function should work the same for C++ and C# targets.
Old solution:
target_link_libraries(C++Target LINKING_TYPE CSharpLibrary)
target_compile_options(C++Target LINKING_TYPE "/AI${PATH_TO_DIR_WITH_CSHARP_DLL}")
Desired solution:
target_link_libraries(C++Target LINKING_TYPE CSharpLibrary)
Summary of results:
With old solution everything works properly, but to make it in this way I must have some "if" construction in my CMake to detect that added library is C# library.
When I make it in this desired way I get compilation error.
foo.cpp(10): fatal error C1107: could not find assembly 'C#Library.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable
So I wonder if there is some way of simplifying this dependency adding? Maybe I can set some property of C#Library?
Update after comment of squareskittles:
My if-construction looks like this
if(NOT IS_IMPORTED)
if(DEPENDENCY_LANGUAGE STREQUAL CSharp)
target_compile_options(${TARGET} ${LINKING_TYPE} "/AI${PATH_TO_DIR_WITH_CSHARP_DLL}")
endif(DEPENDENCY_LANGUAGE STREQUAL CSharp)
endif(NOT IS_IMPORTED)
and of course I can use generator expressions, but I really don't know if it is human readable
target_compile_options(${TARGET} ${LINKING_TYPE} "$<$<AND:$<STREQUAL:${DEPENDENCY_LANGUAGE},CSharp>,$<NOT:$<BOOL:IS_IMPORTED>>>:/AI${IMPORT_DIR}>")
if-constructions seems to be more clear solution, than that.

How to change the library mode in Dotfuscator using post-build event command line

I'm trying to obfuscate a c# project using Dotfuscator CE tool which comes along with Visual Studio 2010, with the help of following commands I managed to obfuscate the code.
but it doesn't make any changes to the private or public method names, I knew that by changing the 'Library mode' which comes under Assemblies-->Properties, I should be able to rename the functions.
but I do not know how to include the library property within the post build event command line. Could somebody please help..
Thanks in advance.
According to the help text of the dofuscator command line:
Extended Options:
/in:[+|-]<file>[,[+|-]<file>] : specify input assemblies. Use prefix to obfuscate input as public(+) or private(-) assembly, use : after the filename to specify a package type
So, by default just doing /in:foo.exe would mean foo.exe is treated as not being in library mode. To obfuscate it in library mode instead, use the + symbol like so /in:+foo.exe
Eartz,
You are partially right, library mode is disabled by default for exe's, but dll's are the opposite. If you look at San' original post you can clearly see he is obfuscating a dll, hence his issue.

Is there a C# mstest equivalent of system property in Java?

I would like to be able to pass a system argument - "host" to the MStest suite. To create automated jobs for continuous integration, I want to be able to specify the host as a parameter so the tests are run on that specific host. I couldn't find any such option with mstest.
In Java, -Dhost="localhost" would work which can be specified as a parameter for the running VM. Is there a similar way in MStest for C#?
There is not an equivalent to the Java system properties that you mention. Here are a couple of ideas on how to approximate what you are looking for:
[1]
Visual Studio test support does include Test Run Configurations (renamed Test Settings in Visual Studio 2010). This is a file that specifies many settings that control aspects of the test run. For example, you can deploy additional files alongside your test, or run a "setup" batch script before your test run begins.
If you have a finite set of hosts, you could have a separate test run config/test settings for each host. Each config/settings would deploy a file that contains the name of a different host. You could then read in that file as part of your unit test setup, perhaps from your [TestInitialize] method. A bit hokey, but maybe it would do what you want.
[2]
You could set a system environment variable (e.g., "TESTHOST") before running the test, and then read that environment variable from your tests. You could wrap all of this up in a simple program or batch script that accepts an argument to set the environment variable, invoke mstest, and unset the environment variable afterwards. For example, this StackOverflow post may give you some ideas on how you might do something like this using PowerShell.
I don't believe there is an exact equivalent. Instead, try leveraging .NET configuration files:
Add an application configuration file (App.config) to your MSTest project. Add your "system" properties as keys in the appSettings section. Reference these values in your tests using the ConfigurationManager.AppSettings collection.

How to compile just one file in c#?

In VC++ I can press CTRL+F7 to compile a single file, or right click on a source file ot compile it.
Is it possible to compile a single file (or current file) in C#?
I would like to for example know if my current file has any errors in it without having to compile everything.
For single .cs file compile + run:
In VS 2008, go to "Tools" > "External Tools"
Click on "Add"
Title: Run CSC (or whatever you want)
Command: C:\Windows\system32\cmd.exe
Arguments: /c C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /target:winexe $(ItemPath) && $(ItemFileName)
Initial directory: $(ItemDir)
Check Use Output Window
Apply + Ok
Go to Tools and choose "Run CSC"
If this doesn't work, verify that your paths for cmd and csc match.
No it is not possible to do this in C#.
Unlike C++ a C# file cannot be reasonably compiled on it's own to determine if it has any errors. C++ achieves this through #include statements which allows a .cpp file to understand the declaration of types available. These declarations define the structure of types the current file depends on and allows the compiler to ensure they are used according to specification.
This process is handled implicitly in C#. The set of declarations available is simply the set of all declarations in all compiled files which are otherwise accessible. There is no way to forward declare dependencies in the manner C++ does and hence no way to ensure they are being used correctly within a single file.
A Visual Studio add-in tool like ReSharper is a very good investment for this situation.
ReSharper performs continuous background solution-wide code analysis and will report issues by conveniently displaying a bar next to your code file\document scrollbar which has red\orange lines denoting any lines of code that have issues\errors. The displayed lines are click-able to navigate to the line in question and also have tool-tips detailing what the exact problem is:
http://www.jetbrains.com/resharper/features/code_analysis.html#Continuous_Code_Quality_Analysis
http://www.jetbrains.com/resharper/features/screenshots/50/marker_bar.png
The issues\warnings that ReSharper can check for are configurable (but it has excellent configuration out-of-the-box), and can denote anything from errors which would cause the code not to compile to more subtle issues where it has detected a possible null method call result which has not been explicitly checked for.
In command line:
%windir%\Microsoft.Net\framework\V3.5\csc.exe /target:library File.cs
You could reasonably attach this to the solution explorers context menu through Tools->External Tools
set the arguments to /target:library $(ItemPath)
something like that might do what you want. Though the file would have to depend on no other files in the project or in referenced binaries aside from what's in the GAC.
Shift-F6 will compile the current assembly, which is almost what you want.
Yes it's possible. You can call the compiler directly using command prompt. i.e.
Create single file 'hello.cs'
Open the Visual Studio command prompt
Navigate to the directory that has 'hello.cs'
Run csc hello.cs
Execute your single file by typing hello.exe
This will at least tell you whether a single file compiles or not. You can find more information here: https://msdn.microsoft.com/en-us/library/78f4aasd.aspx
Yes, this can be done using the Mono .NET Framework. At the command prompt, run mcs path/to/file.cs.
From the Mono docs:
To compile, use csc:
csc hello.cs
Note: csc compiler is not available on all platforms or in very old Mono versions, in such cases use mcs instead.
The compiler will create “hello.exe”, which you can run using:
mono hello.exe
Using Visual Studio 2022 csc.exe
navigate here in PowerShell:
PS C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\Roslyn
compile single file into dll or exe:
.\csc.exe -target:library -out:"C:\Users\quick\OneDrive\Desktop\C#\PerpetualCalendar\PerpetualCalendar.dll" "C:\Users\quick\OneDrive\Desktop\C#\PerpetualCalendar\PerpetualCalendar.cs"
cs file needs Main Method
.\csc.exe -target:exe -out:"C:\Users\quick\OneDrive\Desktop\C#\PerpetualCalendar\PerpetualCalendar.exe" "C:\Users\quick\OneDrive\Desktop\C#\PerpetualCalendar\PerpetualCalendar.cs"

Categories