Compile C# project without VS - c#

I plan to use Sublime Text 2 as my code source editor for C#/Java projects and I don't want to install Visual Studio, so can I compile C# project from CLI?

MSBuild is the build system that Visual Studio uses - you can use it directly with solution and project files as they are msbuild files.
It comes with the .NET redistributable downloads.
Note that for many types of solutions you will need to install auxiliary tools (for example resgen if you have any resource generation happening).

Basically, you can use csc.exe tool, located in c:\Windows\Microsoft.NET\Framework\framework_version\ to compile source files(C#) into executables.
You can create your custom scipt using it and run it to get exe or dll.

VS is way more then wrapper for compiler :)
You can configure VS to open files with external tools.
Just right click file in solution explorer and choose Open With... Then specify path to your favourite editor and set it as default.

The only "serious" option left is http://monodevelop.com/

You can use NANT to do so. But you need to have installed the "Windows SDK".

Related

Visual Studio - Use custom build in CEFSharp

I had successfully built the CEF with proprietary_codecs enabled, but not getting any way to use that inside my Visual Studio project.
Below is my binary_distrib structure. I just made x86 Debug-build
Currently in my Visual Studio (WPF C# Project) I'm using NuGet for CEFSharp, how I can replace the cef binary of nuget with my own built?
I need it cause by default CEFSharp not support any video codec so I needa use my custom built
I am more familiar with nuget. Not sure your issue is related to nuget. As a suggestion, you should use some scripts,especially, automate-git.py command-line arguments
And also do not forget to use the system environments to include them.
You can check this similar issue and this document.
Besides, if this do not help, please contact with CEF Forum.
Well we are using the CefSharp windows forms. We also replace CEF build to enable proprietary_codecs.
After you build your CEF and you must make sure you are building a matching version for the nuget, you should get the following files (some are optional) from the folder (\chromium_git\chromium\src\out\Debug_GN_x86) ..
locales folder
swiftshader folder
cef.pak
cef_100_percent.pak
cef_200_percent.pak
cef_extensions.pak
chrome_elf.dll
d3dcompiler_47.dll
devtools_resources.pak
icudtl.dat
libcef.dll
libEGL.dll
libGLESv2.dll
snapshot_blob.bin
v8_context_snapshot.bin
Copy these files to your application output folder which will replace the files from the nuget.
For our case, we have copied these files to a folder next to our project and it is included in our git repository, and in visual studio we use after build events to copy the files after each build.

I want to make installation of my Visual Studio 2017 project , how to achieve that?

I have database,images and text files in my project and i would like to make instalation..
Also I would like to put prerequirements so that people who install this must install version of .net framework i used in my project
What is the best way to achieve that?
UPDATE:
I wanted to use microsoft visual studio installer but it doesnt work .. it doenst create exe file and i cant open app
I've personally used NSIS for making installers. It has an extensible scripting bit to put whatever prerequisites you need(TOS, EULA, ect.) and it can easily create a professional looking installer.
Try using Inno Setup. It has a good scripting language along with a wizard if you don't want to script. It's also free (unless you are deploying commercial applications).

Is there a simple way to make Visual Studio 2015 use a specific ToolsVersion?

When building a project or solution using a specific version of msbuild I can select an earlier .net toolchain by using the /toolsversion or /tv switch:
"C:\Program Files (x86)\MSBuild\14.0\bin\msbuild" /tv:12.0 amazing.sln
This Just Works for all versions of msbuild, and the version of csc.exe etc. is correctly chosen based on the above:
> "C:\Program Files (x86)\MSBuild\14.0\bin\msbuild" /tv:4.0 amazing.sln
...
CoreCompile:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe ...
...
> "C:\Program Files (x86)\MSBuild\14.0\bin\msbuild" /tv:12.0 amazing.sln
...
CoreCompile:
C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe ...
...
If I don't specify /tv, then depending on which version of msbuild I'm using and a number of environment variables, I may get any of:
The ToolsVersion specified in the top-level element in the project file
The ToolsVersion corresponding to the version of msbuild.exe I'm using
A value from msbuild.exe.config
A value from the registry
(See the different versions of the Overriding ToolsVersion Settings page on MSDN).
So, in order to have builds that have consistent results on the build server and on my local machine, I use /tv when running msbuild.exe (in fact, this is enforced in a psake script, which also ensures it uses the corresponding version of msbuild.exe).
However I cannot use the /tv switch when building with Visual Studio. Instead, Visual Studio 2013 and up will use the .net toolchain that shipped with that version of Visual Studio unless:
The environment variable MSBUILDLEGACYDEFAULTTOOLSVERSION is set and...
...all the project files have the ToolsVersion attribute set to the version I want to use.
This is so baroque that I cannot believe anyone is actually doing it. My questions are thus:
Is anyone doing the MSBUILDLEGACYDEFAULTTOOLSVERSION thing?
If not, is there another way to make Visual Studio use a specific ToolsVersion short of using the version of Visual Studio that shipped with that ToolsVersion? Something that could be stored in version control (so in a project or some other settings file) would be ideal.
And lastly:
Should I even care? Given that each successive version of the C# compiler should be able to handle previous versions' input, and I can set the target .net framework and C# language level in the project file, is this enough to ensure repeatable builds?
(My prejudice is that I should care, since:
I want builds in the IDE and on the build server to be the same (of course)
I want to be able to use VS2015 (and future versions) because it's a better IDE than previous versions, but I don't want to be obliged to use the new toolchain until I decide to.
Perhaps I want too much...)
For a concrete example of the problem, please see my msbuild-vs-vs2015-toolsversion repository on github.
Some background: I'm asking this because we recently had a CI build error when one of my colleagues submitted C# 6.0 code that compiled fine with Roslyn on their copy of Visual Studio 2015, but failed in CI because that uses the previous release of the .net toolchain (they'd used an automatic property with no setter, which is fine in Roslyn but not in earlier versions). We will be updating the CI build to Roslyn, but I wanted to see if we could prevent this sort of thing happening in the future.
I solved this by writing a Visual Studio extension that temporarily sets the environment variable MSBUILDDEFAULTTOOLSVERSION for the duration of a build; the value to be used is read from a file .toolsversion in the same directory as the .sln file. The psake script reads the same .toolsversion file and passes the value to the /tv switch.
The code for the extension can be found here: https://github.com/guyboltonking/set-toolsversion-extension. Sadly, I'm not working with C++, or indeed with Visual Studio, at the moment, so I can't provide any support for it (but I can tell you I used it with no issues at all for several months).
Kudos to #efaruk for reminding me about the existence of MSBUILDDEFAULTTOOLSVERSION.
Edit: Thanks to #mbadawi23, it's now possible to use the extension with both VS2015 and VS2017.
To force a specific C# version in Visual Studio 2015, you can go into the project properties -> Build -> Advanced -> Language Version.
If you set this to 5, the compiler will complain about C# 6 features with: Feature '...' is not available in C# 5. Please use language version 6 or greater.
Alternativly ReSharper also has some tools for this.
Note: You can always create an msbuild file to build your project from using it or changing your project it self and you can decide your tool version conditionally (https://msdn.microsoft.com/en-us/library/7z253716.aspx) (.csproj is also a structured msbuild script with different extension and it will be also compatible with VS).
Regards...
Edit:
https://msdn.microsoft.com/en-us/library/bb383985.aspx
by setting the $(ProjectToolsVersion) property on a project within a solution. This lets you build a project in a solution with a Toolset version that differs from that of the other projects.
So, I think you have got your answer ;)
What you see within Visual Studio (the tools etc) and the code behind them are not what is included in the compiled data they are merely a visual/readable representation, when compiling them as an earlier version of VS you are making the executable of that version.
Please keep in mind that if compiling as a previous .NET version you will potentially lose functionality such as async functionality.

Creating a dll from classes in c#

I have a few classes with the same namespace, and I want to put all of them in a dll file, and use it in other places.
I read the guide on Microsoft's website:
http://msdn.microsoft.com/en-us/library/3707x96z(v=vs.80).aspx
They suggested this:
To build the file [myDllName].DLL, compile the two files [myClass1].cs and
[myClass2].cs using the following command line:
csc /target:library /out:[myDllName].DLL [myClass1].cs [myClass2].cs
I wrote it in a cmd window and got an error that there is no such command as csc.
Plus, how it will find my files without a path?
So what is the right way of doing it? Where should I write it?
I saw some posts here with Library classes.. but not sure how it can help me.
My classes are in a different solution, and I just want to use it as an external dll, and not within the same solution.
In this case, Microsoft's guide seems perfect, if it will work.
If you use the Visual Studio Command Prompt window, all the necessary environment variables are set for you. In Windows 7, you can access that window from the Start menu by opening the Microsoft Visual Studio Version\Visual Studio Tools folder. In Windows 8, the Visual Studio Command Prompt is called the Developer Command Prompt for VS2012, and you can find it by searching from the Start screen.
source
You can run the vsvars batch file from a command prompt and it will set paths for you, for that instance of cmd.exe
Mine is here:
>"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"
Why don't you just create a separate 'Class Library' project in your solution in Visual Studio?
You can than easily add it as a project reference to all other projects that need it.
You can create Solution Folders in VS to logically group projects.
Make sure csc.exe is in your PATH environment variable.
You should have a vsvars32.bat that was installed with Visual Studio. You can run that to automatically add it to the path, or dig down in regedit to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP
Look through the subtrees in there for your framework version, and for an InstallPath key. That should tell you what directory to look in.
You can then use that, and:
WHERE /r "the_directory_you_found" csc.exe
to find the path. Add that to your system environment variables, and you should be able to find it.
As for the path of the class files, either run the command from the directory they're in, or specify the path when specifying the class files.
If you have Visual Studio installed, you could try creating a 'Class Library' project; Or you can run csc.exe by Launching "Visual Studio Command Prompt".
If you don't have Visual Studio installed but have .net framework installed. You can run csc.exe from the framework installation directory.
Installation directory path for .net Framework 4.0 :
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319

How to download and compile a source from an apache project if I have the link (svn)?

Lets say I have this link here: https://svn.apache.org/repos/asf/chemistry/dotcmis/trunk/ and I would like to download and compile the source on my windows. What is todo?
There are a lot folders, classes and some bats. I could download them via browser, one by one - but im sure this is not the way how I should do that. Do I need a special svn tool? And after that? I just have to load the porject in Visual Studio and thats it? I dont thinks so. Any step by step guides or ideas? Thank you
From the download page:
DotCMIS requires the .NET Framework version 3.5 or higher. It does not depend on anything else.
So yes, you should be able to do an svn checkout using your favorite SVN client (for example from a commandline tool, from TortoiseSVN or from AnkhSVN), build the project and profit.
If you're just interested in using the client, the download page also links to the binaries you can just download and add a reference to.
Install TortoiseSVN (or another SVN client) and give it the connection settings.
Then do a full checkout into a folder on your local machine
Also this tool AnkhSVN comes with an integrated add-in for Visual Studio that allows you to perform some operations directly inside the VS IDE.

Categories