Visual Studio (VS IDE) You must know the features and tricks-". NET must-Know series "

Source: Internet
Author: User
Tags rar connectionstrings

Objective

This article mainly describes some of the Visual Studio development needs to know the few and more practical features, but also many people ignore the part. Some of the less common and unpopular features are not in the scope of this article, of course the tail of this article. NET must know series "is purely a fantasy, if there is similar, the basis of passion.

Directory
    1. The use of the Web.Release.config and Web.Debug.config in Web. config when you publish a website project version.
    2. Under Project properties, use build events.
    3. Quickly analyze how unknown schemas and class call structures (vs2010/2012).
One: Use of Web.Release.config and Web.Debug.config

Sometimes the configuration in Web. config may not be the same when we develop and publish it, such as a database connection string. How do you want to automatically replace the contents of the Web. config file when you publish it? In particular, the development of the project to the post-configuration node more and more, common parts and differences are often used <!--annotation---to switch nodes, it is not too much trouble, and now we have to solve this problem, of course, this is only a demonstration of a more common way, as for other ways not to make statements.

This is what you see, the 3 people you see, but the following 2 are generally not used. configuration file, Web.release/debug.config content description (default new project will be generated automatically)

Here are the configuration files for Web.Release.config and Web.Debug.config

<?XML version= "1.0" encoding= "Utf-8"?><!--For more information on using Web. config Transformation visit http://go.microsoft.com/fwlink/?LinkId=125889-<ConfigurationXmlns:xdt= "Http://schemas.microsoft.com/XML-Document-Transform"><!--In the example below, the "setattributes" transform would change the value of "connectionString" to use "Releasesqlserver" Only if the "Match" locator finds an attribute "name", which has a value of "MyDB".-<connectionstrings > <add name= "appconnection"  Connectionstring= "Fill in" here "test environment connection string" or "formal environment string" respectively written in Release.config,debug.config " Xdt:transform= "SetAttributes"  Xdt:locator= "Match (name) /> </connectionstrings ></ Configuration>          

The following is the configuration file for Web. config

<?XML version= "1.0" encoding= "Utf-8"?><!--For more information on how to configure your ASP. Application, please visit http://go.microsoft.com/fwlink/? linkid=301880-<Configuration><ConnectionStrings><AddName= "Appconnection"ConnectionString= "Default connection string"/><AddName= "Testcommon"ConnectionString= "Public use of connection string"/></ConnectionStrings> <system.web< Span style= "color: #0000ff;" >> <compilation = "true"  targetframework = "4.5" <httpruntime targetframework= "4.5" /> </system.web ></ Configuration>          

Note that I set up 2 sub-nodes under the connectionstrings node of Web. config to compare post-release effects, and when published it becomes

The following is the configuration file for post Web. config

<?XML version= "1.0" encoding= "Utf-8"?><!--For more information on how to configure your ASP. Application, please visit http://go.microsoft.com/fwlink/? linkid=301880-<Configuration><AppSettings><AddKey= "Webpages:version"Value= "3.0.0.0"/><AddKey= "Webpages:enabled"Value= "false"/><AddKey= "Clientvalidationenabled"Value= "true"/><AddKey= "Unobtrusivejavascriptenabled"Value= "true"/></AppSettings><ConnectionStrings>//Note that the string here has changed to become a string in the Release configuration file<AddName= "Appconnection"ConnectionString= "Publish Environment connection string"/><AddName= "Testcommon"ConnectionString= "Public use of connection string"/></connectionstrings > <system.web< Span style= "color: #0000ff;" >> <compilation = "4.5" /> <httpruntime = "4.5" /> </system.web>< Span style= "color: #0000ff;" ></configuration>     

This automatically replaces the node that needs to be replaced in the Web. config in accordance with the set mode of processing, the following specific look at the Language bar.

Here are 2 important statements that are xdt:transform= "SetAttributes" xdt:locator = "Match (name)" These 2 configuration properties mean, put the web. config the connectionStrings corresponds to the node property of name Appconnection.

The syntax here is derived from the xmlns:xdt= "Http://schemas.microsoft.com/XML-Document-Transform" namespace, and the 2 separate files need to be imported in order to be used.

Simply talk about common configuration Properties 1:locator properties

(1) Match;

Here you need to just match the property name in your directly.

<connectionStrings><name= "Northwind" connectionString= "Connection string Detail " providerName=" System.Data.SqlClient " xdt:transform=" Replace " xdt:locator/ ></connectionStrings>           
View Code

The engine will then find the matching name Norhwind in your Web. config and replace it with the configuration file graph above.

(2) Condition is based on XPath and uses logical judgment expressions in locator.

 <connectionstrings ><add name= "Northwind"  Connectionstring= "Connection string detail"  Providername= " System.Data.SqlClient " Xdt:transform=" Replace " Xdt:locator= "Condition (@name = ' Northwind or @providerName = ' System.Data.SqlClient ') "/></ Connectionstrings>         
View Code

Above is the Name property that matches the ' norhwind ' or providername match system. The configuration file node for the data.sqlclient will be replaced.

2:transform Property

(1) Replace means that all matching nodes are replaced

<Xdt:transform= "Replace"><assembly/></Assemblies  >        
View Code

In fact, this describes the file when Web.release.config, the file that will be replaced when web. config. (2) remove removes the first matching element.

<xdt:transform="Remove" ></assemblies>   

(3) RemoveAll

<connectionStrings><xdt:transform= "RemoveAll"/></  ConnectionStrings>        
View Code

(4) Insert

Insert from parent node (insert <deny users= "*"/> in authorization)

<authorization><users= "*" xdt:transform= "Insert"/></  Authorization>          
View Code

(5) SetAttributes

<compilation  Batch= "false"    xdt:transform= "SetAttributes (Batch)">< /Compilation>        
View Code

This feature and tips are probably here, detailed configuration reference below Microsoft Official documentation

https://msdn.microsoft.com/zh-cn/library/dd465326 (v=vs.100). aspx

Two: use of "build event" under Project Properties

What is a build event, you can use a build event to specify a command to run before the build starts or after the build completes. The build event is only executed when the build successfully reaches these points in the build process. It is easy to understand that after the project has been compiled, you need to do something extra, this in C # code can not do, so generated events come in handy.

See this figure is not very familiar with, but the specific use of the students have how many ^_^.

Build events are divided into command functions executed before and after build, and post-build events can be specified

3 Compile Condition Options

examples of common build events: Post-build DLL replication, transfer

Example one:

I have a solution "Nettoolstudio" This is a plug-in project for me, due to "NTS. SQL Server "This assembly is only a subset of plug-in implementations, so it is not dependent on the main frame, not automatically copied to the Bin directory, and will not help me to copy to the" Dbprovider "place the plug-in folder, so I need to copy the Nts.sqlserver generated DLL to" Dbprovider "directory. But every time a manual copy is cumbersome, generating events comes in handy, and the command line in the build event is a DOS command, and in the post-build event command line, enter thecopy or xcopy [source file full path] to the path .

xcopy/r/y $ (TargetPath) $ (solutiondir) nts\dbprovider\

This creates a DOS command

Of course, you can also write more than one command statement.

You see there's $ (TargetPath) $ (solutiondir) What are these? Open the macro in the build event as shown in.

Look at the fight, so we can get the assembly and the solution to some of my macro commands, as to what is a macro command, here do not explain, can be used just fine.

This feature is probably here, detailed configuration reference below Microsoft Official document

Https://msdn.microsoft.com/zh-cn/library/ke5z92ks (v=vs.100). aspx

Sharing a few good batch processing, is also commonly used yo.

Locate the file that is currently executing the directory and copy the. rar "This batch function can copy all DLLs of the current directory into the current Temp folder"

Deletebin.rar "Look at the name to know is to delete all the VS generated bin directory and obj directory, when packaging copy away good helper"

Three: quickly analyze how unknown schemas and class call structures are

We sometimes look at the open source code and the new entry of a company to see the previous colleagues write code is not very tangled, no documents, no architecture diagram, no one asked, but the project has been maintained for n years, it looks disgusting ah, now there are 2 vs comes with features to quickly browse and build their own logic diagram.

Yes, that's what happens when we right-click in the code-editing form, and these 2 code views and call hierarchy charts are a quick way to quickly read someone's code.

1.VS 2010 introduces a new "View call Hierarchy (view called hierarchy)" feature that allows you to quickly discover where a particular method or property in your code base is being called, Allows you to quickly traverse (traverse) The call tree of the entire code base (without having to run or debug the scenario).

2. The above code view, Microsoft is called "Code Map Understanding Complex Code"

First look at "View hierarchy of calls"

Right-click on the method name-"View the hierarchy of the call, and wait a few seconds to appear as

Then click on the "Updatekeywordtofile" node inside, you can continue to expand.

See is not very cool, specific how to see, please look at the red logo, hurriedly to try it, specific there are many features, there are many surprises.

Take a look at the code (Class) Reference graph "code map Understanding Complex Code"

Right-click on the "Class" or "method" name to find all references in the code, wait a few seconds (see machine performance) to appear as follows:

Right-click Method

Right-click Class

If you think it is just a look at it is wrong, when we debug can also show the specific location and level of the yourselves call method, can see the sequence of calls before and after.

When I break the point, the right image will also display a breakpoint icon, identify the specific location of the run, if you have many methods in index, you can right-click to add to the map view on the right, adjust the number and level according to your preferences.

Visual Studio (VS IDE) You must know the features and tricks-". NET must-Know series "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.