Shared resources Visual Studio 2010 - c#

So I have a solution which contains 4 projects, a "Core" Project which is the actual application (as a class library), and 3 wrapper projects, "Console", "WinForm" and "Service" which basically wraps a Facade class in the core class and contains various settings to handle different logging strategies for each different application (Console/Trace/File) and launch the application as either a Console, WinForms or Service, depending on how the customer wishes to deploy the application.
In the Core project I have 3 resource files which contain simple template views for the Nancy web framework. However the way Nancy looks for these views are on the current path. Since the files in the Core project aren't on the current path for any of the 3 other projects I need a simple way to access these files across projects.
Somewhat naively I thought this was where the concept of a "Solution" came in, to handle dependencies between projects. However by searching the Internet, much to my surprise, it appears there is no elegant way to do this. The only two solutions I've been able to find involves copying the files to a scratch/temporary or directory in the solution, and copying them to the respective needed directories later, as post build actions, and Adding an item manually using "Add as Link". Now while both these solutions technically work, the first leaves (possibly out-of-date) build artefacts lying about where they don't really belong (IMHO), and the second is tedious, time-consuming and prone to human error (because you can't just link to a directory).
Are these really my only two options, or is there some third, totally obvious way I've just missed because I'm new to Visual Studio?

You could use a custom IRootPathProvider in Nancy, if the only things you need are Nancy specific.
The other option is to link a folder - you can do this, but it involves manually hacking on the csproj file, there's a few questions on here about it, including this one:
Visual Studio Linked Files Directory Structure

Nuget is a package management system, that I have used to share artifacts between projects as dependencies. You could include libraries available via nuget.org or have your own nuget packages defined.
Teamcity has got good support for generating nuget packages with every build and can serve as a Nuget server.
Here is a reference to include files into a nuget package.

Related

How to hide my test framework code and give the posibility for other testers to only be able to write features?

I have a test framework written in C#, I am using Selenium, nUnit and Specflow.
Visual Studio is the tool and I have the normal project folder structure (pages, hooks, steps, features).
Testcases are associated with AzureDevOps and the code is pushed to the repo and pipilines are working great.
My issue is that I want to hide the code under the level of the features.
The idea is that other people could create new feature files and create tests within them, but I do not want them to be able to see the code that is under those Gherkin sentences.
So they should be only able to create and write new features, but not seeing the code below.
Could you please give me some ideas how this can be achieved?
You can import bindings from external assemblies. In SpecFlow.json, add:
{
"stepAssemblies": [
{
"assembly": "Name.Of.Your.StepDefinitions.dll"
}
]
}
While this is typically used as a means to reuse step definitions in multiple projects, you could use this to "hide" the step definitions from test writers. The step definitions would be a pre-compiled DLL file that they can import into a different Visual Studio solution.
This requires two different solutions in Visual Studio:
A regular class library that holds step definition classes. You will probably need to choose .NET Core or .NET Framework 5+, since it must integrate with a unit testing framework. I don't believe .NET Standard would work (but you can certainly try).
Another Visual Studio solution that testers can use, which contains the feature files. This project would reference a DLL file you would create from project #1.
The challenge is disseminating this DLL file. Any update you make would need to be given to the testers' Visual Studio solution. A couple of options come to mind:
Manually update solution #2.
Create a NuGet package for solution #1. Set up a build pipeline in Azure DevOps to build, package, and push this NuGet package to your project's "Artifacts" feed whenever you make code changes. Someone (you or a tester) would need to update that NuGet package in solution #2.
As an alternative, give everyone access to the features and step definitions, but enforce a pull request policy on the repository requiring you as a reviewer. That way you can protect the main branch as the gatekeeper. Testers can submit changes to step definitions, and you are free to reject their pull requests if the changes are not satisfactory.
This, of course, depends on the team structure. If you have outside contractors, sharing the step definition code might not be desirable. Just don't limit people's abilities simply because you don't trust their skill level. Use pull request policies requiring you as a reviewer if they change step definition files. This allows you to benefit from someone else's labor while still giving you control.

Building one web project breaks the compiled version of the second in solution

I have a big solution with 30 projects of which 2 are web projects (MVC and WebAPI) with a bunch of background class library projects.
I have visual studio set up to host the web projects in IIS.
If I do a clean build, followed by a full build of the entire solution, then accessing both projects via a browser works fine. (they are in diff folders and hosted on diff 'domains' in iis)
If I make NO code changes, simply rebuild one of the 2 web projects, the OTHER one stops working.
To be clear, rebuilding the WebAPI project causes the MVC project to have errors. And vice versa.
The error I get is saying that System.Web.Http.Formatter is not found. The detail says that the located assembly version is different from the reference version. Checking the bin folder shows that that is not the case.
Make sure that all the solution's resources are up to date. If you use Nuget, update all packages in all projects (back up first!). It sounds like you have a version mismatch, where functionality is missing in DLLs copied to the output directory for the solution. It may involve changing some entries in the Web.config of each project, but without access to the code, it's hard to know for sure.
Report back once you've updated every library, and made sure the versions match across all projects in the solution.
In addition to Apache's and Steve's suggestions, I'd also recommend deleting the files in your Temporary ASP.NET Files directory. If you're curious here's a good write-up of what the contents of that folder are for.

Shared Project for ASP.NET

I have two ASP.NET web projects and they share a lot of images and JavaScript files. I tried to create a shared project and linking it into both ASP.NET csproj files:
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
But images inside the shared project are not found during debugging with IIS (Browsers "image not found" image is displayed). But Visual Studio recognized them and showing the image files in IntelliSense.
Any ideas?
You still can bundle resources with project and distribute it, but you nee to create nuget package.
create project
make nuget package
publish it to private feed (e.g. myget.org)
add reference to your feed from client projects
PS: Only content of folder 'Content' included in nuget package.
Apologies for the speculative answer, but hopefully this will help someone;
This is a struggle I'm currently facing too (which is concerning, as nearly two years have passed with barely a mention).
I have also had to manually add the Import line to each solution as it appears you have.
I think the issue is with the inbuilt debugger not knowing how to serve the files properly. If you deploy the compiled solution to any instance of IIS it appears to work correctly.
I am experimenting with the inbuilt debugger to see if I can get it to work, but am quite confident I'll have to use a local IIS instance moving forward.
Shared projects provide invaluable functionality, so it's a shame it's still not natively supported.
At the end of the day your images have to actually be somewhere, you can't just reference them from another project. It would work if this other project was hosted in IIS, given a domain, and you referenced the images from this domain. Perhaps call it your CDN.
When you reference a project to get at classes etc, the project is bundled up in to a dll and packaged along with the main project. Images, js files etc can't be bundled in to a dll, and will not be copied across to your project.

TFS Build Issues With Multiple Versions of the Same Assembly in Different Projects

I keep running into an issue with our TFS build server. I've got 2 projects (both in the same solution), 1 is a WebForms project, running .Net 4.0. The second is an ASP .Net MVC5 project running .Net 4.5. There is also a Silverlight project, but the problem is reproducible with just the first two.
Both of these projects use NuGet packages for various libraries. Sometimes there are different assemblies within a package for their respective environments. A .Net 4.0, 4.5, SL assembly, etc.
The build server seems to dump all of the libraries required into a single folder, then pulls from that to build the solution. This causes problems in many cases, with the wrong project getting the wrong assembly version. This does not occur locally, only on the build server. I can't figure out what I need to do to keep this from happening. Any ideas?
Yes, I hate this standard behavior, but TFS will output everything to the same folder by default, and then you will get various errors depending on which order msbuild compiles your projects if you have references with the same name or even project outputs with the same name.
The easiest workaround is to use the AsConfigured option on the Process tab, '2. Build' -> 'Output location' of the build definition window. This keeps your normal source structure intact, but I think you will lose support for automatically dropped outputs (i.e. you will have to provide a script to do that yourself). If you are only using TFS Build for validation, this is the cleanest approach.
You can also use the PerProject setting and split up your projects into two distinct solutions, perhaps suffixed by platform (we've done that numerous times in our company). Then, you specify both solutions to the build process and it will create two separate folders in the output, one for each solution.
This is all assuming you are using TFS 2013. In TFS2012, there is a similar option but it is in '3. Advanced' -> 'Solution Specific Build Outputs'. You will probably have to go this route if you are using TFS2012 or you will need to modify the default workflow yourself to add your own logic.
EDIT:
From your comment to the other poster I see you are using TFS 2010. Well... I think this was absolutely not supported at that time, I remember having similar problems, but we upgraded to TFS 2012 and all was well.
I think your only option is to either create two separate build definitions and build each solution that way, or you will need to checkout the xaml workflow and edit it with your own logic. Perhaps downloading the TFS2012 template and "porting" it to TFS2010 would be a better approach since at least you would not be reinventing the wheel that way.

Visual Studio Multi-Project Solution Options

I have a VS2003 solution with 21 ASP.NET 1.1 projects in it. My goal is to eventually migrate them to 2.0 and then 4.0. There are mainly internal admin apps for different departments.
I want to create a multi-project solution now in VS2010 and migrate/re-code these one at a time in ASP.NET 4.0 Web Forms in VS2010. There will be some artifacts common to all projects such as CSS, scripts and images. Could the use of Resources help with the common files and would it be possible to have a single master page for all projects?
What are the best options for creating a multi-project solution here?
From what I understand, your goal is to share resources like CSS, JS files across projects. One way to do it would be to use linked files in Visual Studio. We do it extensively in one of our solutions where we share many class files and signing keys acorss projects. Linking files basically involves putting the files in one project in the solution and then linking to them from other projects of the solution.
You have to be a little careful though during deployment of projects containing linked files as linking the file does not physically copy the file to the destination project. So even if your project has a css folder, the linked file shown under that folder in VS is not physically there in the directory structure on the disk . If you link classes, the dll for the project that has the linked class file will include the linked class, but for resource files like css, JS and common masterpage, they will not be copied over when you deploy. You can leverage build scripts or some simple batch files to handle those issues. This should solve your problem.
Why not just convert them directly to .NET 4.0?
Beware when you move them to .NET 2.0 that the default project type in Visual Studio 2005 changed from the type of project you're used to in VS2003 to "web site" projects. But with Visual Studio 2010, you've got the same Web Application Project you're accustomed to, so why not just go there directly?
Also, be aware that VS2010 can target .NET 2.0 applications, so there's really no reason to stop there.

Categories

Resources