I wrote many solutions in Visual Studio. Some of them includes components, which intend to be published to Nuget.
Previously, I wrote these projects directly and publish them to Nuget. This is not a smooth way. Consider this: You have project A need to be published to Nuget. Project B, as well. Project C need to reference project A and B, and also need to be published to Nuget. Project D need to reference C for testing. Obviously, following Nuget standard, the Project C need to reference A by using Nuget Packages instead of the projects of A and B directly. But it seems that there is no called testing mode publishing in Nuget supported. There is no easy way to test your project before publishing to Nuget. Maybe you need to change the references in Project C and D repeatedly, switching mode between testing and publishing.
Recently, Shared Project support added to Visual Studio. Now I use a better way, IMHO, in developing such a solution mentioned above.
Create a shared project for each project need to be published to Nuget.
Put all codes into shared project instead of original one.
Create a project for publishing to Nuget, reference the shared project related. — Project N
Create a project for testing, reference the shared project related. — Project T
If your Nuget projects need more references which will be published to Nuget from this solution, add them from Nuget to the Project N, and add them as reference from their Project T to this Project T.
All Project Ns will only be used for publishing to Nuget. As well as all Project Ts will be used for testing. They share the same code but the different source for referencing.
Using an instance built by default parameterless constructor will cause exception or miscalculation. To avoid this, always use parameter-based constructors. This will not be fixed due to consideration about running speed.
Microsoft digs lots of pits, and I keep jumping among them.
Recently, I wrote a program using HttpClient in dotNet to post some data to server through HTTP Post. The server is set with client certificate required.
My designing is simple:
Open X509Store to query the certificate by using thumbprint.
Attach the certificate found in step 1 into WebRequestHandler.
Pass the handler created in step 2 to the instance of HttpClient and send the request.
Required by step 1, I need to type the thumbprint of the certificate into code. The steps I did:
Open certificate from Windows. It’s shown up like this:
Copy the text of Thumbprint and paste it into a notepad.
Replace all spaces to nothing.
Copy the new text into code.
When I run the code, it ended in a strange way. No certificate is found by using the thumbprint I provided. I dig a long time before I found this pit prepared by Microsoft: The text, copied from the window above (in step 1), contains hidden lead bytes “0x200E”. These bytes won’t display in code view of Visual Studio, nor in Notepad.
I have multiple devices installed with Ubuntu Server. Some of them have a strange problem:
They can access internet using some applications, such as squid, without any problem.
They can ping to internet IP address.
They can use host / dig to query IP by domain name.
They cannot ping to internet by using domain name directly.
They cannot download file through wget / curl using domain name, but can do with IP.
They cannot use apt, stuck at connecting.
All they use a local dnsmasq as their dns.
After a long time dig, I found the problem and here is the fix.
open the file /etc/nsswitch.conf, search the line with “hosts:” and change the setting to “files dns” (without quotes).