I'm creating integration tests (web class library project) for my ASP5 MVC6 application. I want to add a resource file with raw SQL to the test project for DB preparation.
I wanted to use good old resources (.resx). But I it's not available in add new item project's menu.
I found this answer pointing to a github repo. I guess this is where he reads the file:
using (var stream = FileProvider.GetFileInfo("compiler/resources/layout.html").CreateReadStream())
using (var streamReader = new StreamReader(stream))
{
return streamReader.ReadToEnd().Replace("~", $"{basePath}/compiler/resources");
}
I tried using System.IO.File.ReadAllText("compiler/resources/my.sql") in my test helper project in TestHelper class.
When I used the TestHelper class in my actual test project it was looking for the the file in test project directory.
TestProject/compiler/resources/my.sql insetad of TestHelperProject/compiler/resources/my.sql
I can figure out a couple of workarounds. However I'd like to do it the right way. Preferably like I would do in with a resx file:
string sql = Resources.MySql;
Any suggestions?
EDIT
Project type
Available items
It is a little more complicated because there's no tooling support but it is doable:
Create a resx file or copy it from somewhere else like a classic C# project
If you can use sake as the build system, then you can use the same target that we, the ASP.NET team use: https://github.com/aspnet/Universe/blob/dev/build/_k-generate-resx.shade otherwise, you need to implement something similar in your own build scripts
Place the resources either compiler/resources. If you place them under any other folder then include them in the project json (like here)
Build using sake then build using dnx. Your resource should be available as a strong type object
Related
I have an older asp.net solution consisting of several projects. The data access layer is contained in a separate class library project while the frontend is in another project.
The data access project is using Application Settings (https://msdn.microsoft.com/en-us/library/a65txexh.aspx) for several settings, among others 3 connection strings. I have a /Properties/Settings.settings file which - when changed - results in an updated /app.config file.
My problem is that I haven't found any way to automatically change these settings when building and publishing the solution.
I know about web.config transformations (https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx) and that Visual Studio offers the ability to create a so called "Config Transform". But as far as I know a class library doesn't have a web.config file and this menu option is not available for neither the Settings.settings file nor the app.config file.
Is there a way to automatically change the settings.settings file/app.config or is there a completely different best practise to provide connections strings to a class library?
EDIT: I should add to the above that the Data Access class library is using Datasets.
I'm trying to use OpenBLAS in a c# project (more specifically I'm attempting to use it with Math.NET via MathNet.Numerics.Control.LinearAlgebraProvider). I've successfully created the files following https://github.com/xianyi/OpenBLAS/wiki/How-to-use-OpenBLAS-in-Microsoft-Visual-Studio.
Now I have a .lib and .dll file in a new directory (as per subsection Use OpenBLAS .dll library in Visual Studio), but I'm not sure where to go from here!
Does anyone know what I'm supposed to do from here? I cannot directly add the generated dll to my project, and from further reading it seems like I need to generate a new dll using Visual Studio.
Use the NativeWrappers solution file provided by MathNet.
Similar instructions for MKL and ACML are here:
http://mathnetnumerics.codeplex.com/wikipage?title=Native%20Providers&referringTitle=Documentation
Can anybody provide some code block to add an existing C# file to a project.
I have 2 projects in my solution. One project generates C# class files which will be use by second project. I have to incluse these generated files in the second project and build the project. It should be done through programatically. I know that to include these files I have to edit the C#project file (which is an XML) and make an entry that file. But I thought of
using existing code if anybody has it.
Thanks
You can ahve a look at the MsBuild.Engine namespace. It allows you to manipulate a csproj in a consistent way so you can oper the target project and add the reference programmatically.
I have already come across the Stack Overflow question "Is there a way to generate a DLL file from Visual Studio Express without explicitly creating a DLL project?", but it does not directly answer my query, so I'm raising it here.
The problem I am facing while trying to make the DLL is that I can't find any option under Build named build class file.
I have changed the project property to class file (shown below)
This is how it is:
And here is how my build option is getting displayed:
Also when I am using the command-line option the dll file is getting generated but it is not getting the properties I'm setting in the application.
I am new with Visual Studio so a litte bit confused about this part.
The "Build Solution" option in your second screenshot is the thing you need to click to produce your dll, alternatively you can right click on your project in the Solution Explorer and click "Build":
(If you only have one project in your solution then these two will both do exactly the same thing)
The output dll will normally be placed in the bin\Debug or bin\Release directory depending on whether you are in Release or Debug configuration, check the "Build" tab of the project properties for the exact path.
The reason why you aren't seeing a "Build class file" option is because this is what the "Build project" menu item does - it will produce a class library if the project output type is "Class Library", a windows executable if the project output type is "Windows Application" etc...
You're not trying to build a class file - you're trying to build a class library.
And you just build the solution - that will build each of the projects in your solution, including your LicenseCheckLibrary project is just a class library project.
It looks like you're basically there - look in the bin\Debug or bin\Release folders under LicenseCheckLibrary, and you'll find the DLL.
Why would you want to avoid building a DLL file in the first place? Are you developing an EXE file in order to test the logic and then conver it to DLL once it is working fine? If yes, why not create two projects: Windows Console and Class Library. Inside Class Library implement the licensing logic and use Windows COnsole to test the logic. When you say you are new with Visual Studio, what exactly do you mean? You never used it before or you are new to .NET Framework programming? .NET Framework has certain classes for developing licenses. Also, there were quetions here on stackoverflow regarding the licensing. Find some of them instead of reinventing the wheel.
Have a look at this article http://www.developer.com/net/net/article.php/3074001
Create a new class library project
Create classes and code
compile Project
Dll Created
Create a new project
Click on Add Reference
Navigate to the class library folder
Go into the debug folder or whatever and include
Remember you will prob have to include the namespace. in the new
project.
Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.
However I can't open the whole project on my Microsoft Visual C# 2010 Express (that also runs C# XNA) because
Solution folders are not supported in this version of the application
Also I just want the class to use separately in my own seprate project.
I tried to copy the three important seeming files Interval.cs, IntervalNode.cs and IntervalTree.cs into my project but this generated the compile error
There are no importers which handle this file type
I've also tried to copy and paste the contents of the three files into my project, encapsulating them into there own namespace as well as there was a lot of code. I had to rearange some of the usings a little but have run into the problem that possibly it wants PowerCollections .dll and .pcb files as using Wintellect.PowerCollections; causes
The type or namespace name 'Wintellect' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure how to continue or if I'm doing the right thing at all in how to get this class to work.
Add the library to your solution
Copy the IntervalTreeLib directory into your solution directory. Then, right-click your solution, and add existing project. Point it at IntervalTreeLib.csproj in IntervalTreeLib, and click Open. That should add the IntervalTreeLib project to your solution.
Add a reference to the library in your project
Then, in your project, add a reference to the IntervalTreeLib proejct:
- Right click the References folder, and Add Reference. Click the Projects tab, and select IntervalTreeLib.
Use the classes in your code
To use classes from the library in your source then, you need to either add:
using IntervalTreeLib;
void Foo() {
IntervalTree<int, int> tree = new ...
}
Or, refer to them by their full name:
IntervalTreeLib.IntervalTree<int, int> tree = new ...
Open the IntervalTreeLib.csproj file if you want to be able to open the project in it's entirety (or in your current solution add an existing project (you can right-click on the solution) and select the IntervalTreeLib.csproj). If you are trying to grab just the code file in your project, ensure you also grab the PowerCollections.dll file (I see it is in the same folder as the code files) or your code will not compile (as you have discovered). You'll need to add a reference to it and include the needed using statement at the top of the code files making use of this library (or use fully qualified name with the namespace).
using IntervalTreeLib;
or
var myObj = new IntervalTreeLib.[WhateverClass](...);
Also, make sure you read the license.txt file. You may need to include it if you are using the code. Give credit where it is due.
UPDATE:
If the test project is causing you problems, just open the library project. Ideally you could just open that and compile it, adding the output DLL files that are generated directly into your solution. This is ideal unless you are planning on changing the library source code itself.
Add the library to the references of the project you want to use it.
Since discussing that you are able to build Intervallib.dll, we will discuss about how you should the dll in your project.
Now in your proj, right click on the references part and add the dll intervallib.dll to your references. In your game.cs file, have the reference to the namespace as -- using IntervalTreeLib;
then you should actually copy the dll powercollections.dll to the bin directory of proj directory also.
you should copy this dll because there is an indirect link to the dll as it is used in IntervalTreeLib.dll
following these steps, I was able to execute this project.