Updating Project References in VS 2019 Community edition - reference

I have a WebApp and several APIs with each one having a project dependency on a class library project. I have changed the folder structure and moved around some of the class (.cs files) within the new folder structure of the class Library project. For example, I created a new Data folder and moved some of the .cs files from the Models folder to the Data folder.
However, whatever I do I cannot update the WebApp and API projects to take account of the new class library structure. I have tried Rebuilding the whole solution, unloading and reloading the class library project etc., but the WebApp and API projects are still bound to the old class library structure and do not recognise the existence of the new Data folder.
Any ideas on how to update the class library reference in teh WebApp and API projects to reflect the changes made?

Related

Setting up a modular project in Android Studio

I'm coming from the Visual Studio world of solutions, where each solution can consist of multiple projects that can refer to each other.
What I want to do is create a modular Android project in Android Studio such that all my code doesn't live in one huge app project. However, it seems terribly difficult to do this, so much so that I am sure I am doing something wrong.
I created a blank project called MyProject. This creates a project with the name MyProject and a package com.sohum.myproject. There is a single app project contained within containing no source files.
I now want to add another module under the same namespace (e.g. com.sohum.myproject.library1). However, it seems when I try to add a new module via the menu, I can only do so into a com.sohum.library1 project. How do I get it to use the same package as the project?
My end goal is to have all my modules under the com.sohum.myproject package, referencing each other. For example:
com.sohum.myproject.application will be the entry point. It might depend on com.sohum.myproject.library1 and com.sohum.myproject.someotherlibrary. And I would like to see all of these modules when I open the MyProject file.
You can click File > New > New Module. Then choose Android Library and enter the details.
Reference: https://developer.android.com/studio/projects/android-library
Another way is to set up the project in a subpackage when creating it.
For example, create a project MyProject in a root directory. Call the application Application and rename the package to be com.sohum.myproject.app instead of just com.sohum.myproject. Now any new modules created will be added below the com.sohum.myproject package space.

How to publish solution with class library projects in IIS

I have an Asp.Net Web Api solution with 3 class library projects that are referenced from the main project. I have published the main project to another server on site - MySite/Main. I am unable to figure out how to publish the class library projects to location like so -
MySite/CL1
MySite/CL2
MySite/CL3
This shall enable the main project to reference them properly. How should I go about it?
When you build your web project all the referenced libraries are being copied to the bin folder (check for yourself). This folder is also being published.
If you use IIS it will automatically look for assemblies in the bin folder so you shouldn't worry about making the folder structure to be the same as in your local environment.
So the only thing you should worry about is referencing libraries properly.
The website project is the only one which should be published. You don't need to publish class libraries (I don't think you can do this using Visual Studio)

Robolectric uses incorrect resource id from library when inflating view

This is not exactly a question as I found the solution for the problem. Just hope it will help others who can encounter it.
We use Robolectric to write unit tests for a project which uses a library (actually several libraries). The libraries as well as application uses a lot of resources.
Lets suppose that Eclipse workspace contain project Library (with "library.package" as top package) which creates an Android library and project Application (with "app.package" at the top) which uses Library. the project Test is Robolectric project which refers to the Application project.
All of a sudden we found that very simple test which checks for existence of a particular view in the activity fails. For example:
#Test
public void testProgressBarInit() {
LoginActivity activity = Robolectric.buildActivity(LoginActivity.class).create().get();
assertTrue(activity.findViewById(R.id.status_text) instanceof TextView);
}
The library project implements the LoginActivity and defines an appropriate resources (layout). Failing tests run perfectly before we changed our code structure a little bit eliminating one more library.
Running the test under debugger showed that findViewById call uses correct value of the R.id.status_text taken from Application/gen/R.java file. At the same time, we discovered that the value of R.id.status text in the Application/gen/R.java differs from the value in Library/gen/R.java. Also, the Appication/gen directory contains file library.package.R.java which contains the same value for status_text as in the Application/gen/R.java (which differs from original one in the Library/gen/R.java). It is normal behavior of aapt tool which can change resource ids while merging resources from the library and the application.
After some investigations we found the following:
Robolectric loads resource IDs which was defined in the library twice: once using R.class from application project and another using R.class from the Library project
which class is loaded depends on the class path configuration
to run tests we need to export the Library project from the Application project
if Library project is exported before Application/gen folder in the class path configuration, Robolectric replaces resource ids by those found in the Library/bin/classes/library/package/R.class
if Library project is exported after Application/gen folder, Robolectric uses correct resources found in the Application/bin/library/package/R.class.
It is certainly a bug in the Robolectric implementation as it should not load resource ids from R.class associated with library package. All ids are propagated to the Application/gen/R.java (see discussion here on GitHub).
If you encounter this or similar problem with resource usage while using Robolectric, make sure that you export library project after Application/gen folder in the Build Path-Order and Export configuration.

Orchard CMS Custom Module Project File

I have an existing solution (multiple projects, one MVC web project) that I'm trying to wrap into an Orchard module.
All documentation says that the web csproj should be at the root under my module directory (eg Modules/MyModule/MyWeb.csproj).
However, I have an existing solution structure where the sln file sits at the top level and each csproj file (and project content) sits in its own directory (the standard solution structure when you build a multi-project app in Visual Studio).
Is there a way I can tell my Module.txt file that the Orchard Module csproj is under MyModule/MyWeb/MyWeb.csproj? I'd prefer to not restructure the whole solution.
Thank you.
Note: As a point of clarification, it is not ~/Modules/MyModule/MyWeb.csproj but ~/Modules/MyModule/MyModule.csproj. The Folder name of the Module must match the file name of the project (before .csproj). This is enforced by the Dynamic Extension Loader, which requires ~/Module/{ModuleId}/{ModuleId}.csproj. (A similar approach is required for themes.)
The only potential way to do this is to write a custom module that follows the above that contains a custom loader. Within your module, create your own implementation of IExtensionLoader, and register it with Autofac. However, I don't know if it would work; I've never tried.
You will probably have an easier time reorganizing your solution.

Which project file element specifies a WinRT class library project and not .NET?

I have a WPF class library that I want to port to be a WinRT class library. My plan is to copy the project, edit the project file so that it's a WinRT project instead of WPF, and see where I stand.
However, I cannot find which element in the project file makes it a WinRT project, and not .NET. Any ideas?
I've tried everything including diffing the project file with a WinRT class library project file, and slowly changing it over, but the WPF project never switches to WinRT in VS's eyes.
Sorry if this sounds nuts, I'm looking for the quickest way to find out how much work I need to do to port across.
Thanks
I'd take a different approach to that:
First I'd create a new Windows Store apps class library project.
Then I'd copy all the files from the existing WPF class library folder to the new Windows Store apps class library project folder (without overwriting any of existing files)
In the Solution Explorer window I'd enable Show All Files to see all the copied files and folders.
I'd multi select all the items in the treeview that belong to the project and click on Include In Project from the context menu.
At this point the only thing potentially still missing would be settings at the project level such as conditional compilation symbols and missing references which could easily be added by comparing both projects in Visual Studio or just trying to compile the new projects and seeing what goes wrong.

Resources