The Borough of Beaver (Borough) appeals the May 19, 1994 order of the Court of Common Pleas of Beaver County (Common Pleas) reversing the December 30, 1993 order of the Borough’s Zoning Hearing Board *158(Board) and permitting the County of Beaver (County) to proceed with building a new jail.1
The County had filed a challenge to the validity of the Borough’s Code of Ordinances (Ordinance), alleging that it excluded the use of land for a jail. The County had also filed, in the alternative, an application for variances from provisions of the Ordinance.2 After two days of hearings, the Board denied the County’s validity challenge and its application for variances. The Board determined that the Ordinance did not exclude the use of land for a jail, because a jail is a type of government office and is, therefore, a permitted use in the C-3 Commercial Professional District. The Board denied the application for variances because it determined that the County had not met its burden of proof pursuant to Section 910.2 of the Pennsylvania Municipalities Planning Code (Code), 53 P.S. § 10910.2.3
The County appealed to Common Pleas, which reversed the Board. Common Pleas first determined that the term “government office” does not include a jail. The Ordinance defines the use of a building as its primary use. The primary use of a jail, according to Common Pleas, is the housing and confinement of prisoners. Common Pleas reasoned that although a jail may contain administrative offices, its primary use is not administration. Common Pleas next determined that the Ordinance excludes the use of land for a jail because the Ordinance does not specifically provide for the use of land for a jail, and Part 2 of the Ordinance provides that “[ujses not specifically listed or defined ... shall not be permitted.” Common Pleas determined finally, that the Borough did not establish the legitimacy of its exclusion because it did not establish that the exclusion protected the health, safety, welfare, and morals of the general public. Having concluded that the Ordinance unlawfully excluded the use of land for a jail, Common Pleas ordered that the County may build a new jail pursuant to either of the plans it had presented to the Board.
The Borough has appealed to this Court and has raised five issues, the first of which concerns whether the County had “standing to appeal a favorable ruling as to permitted use of its property.” According to the Borough, the Board’s decision that a jail is a permitted use in the C-3 Commercial Professional District was a ruling favorable to the County. The County, therefore, was not aggrieved and could not appeal to Common Pleas. Pursuant to Pa.R.A.P. 501, only a party “who is aggrieved by an appealable order ... may appeal therefrom.” The Pennsylvania Supreme Court has stated “that a person who is not adversely affected in any way by the matter he seeks to challenge is not ‘aggrieved’ thereby and has no standing to obtain a judicial resolution of his challenge.” Wm. Penn Parking, Inc. v. City of Pittsburgh, 464 Pa. 168, 192, 346 A.2d 269, 280 (1975). The Board’s order denied the County’s validity challenge and its application for variances. The result of the Board’s order was that the County was unable to build a new jail pursuant to either of the plans it submitted to the Board. Without question, the County was aggrieved by the Board’s order.
The Borough’s second issue concerns whether the County has “standing to attack the validity of the Ordinance since it does not prevent jail or prison use of the land involved.” Citing Jenkintown Towing Service v. Zoning Hearing Board, 67 Pa.Commonwealth Ct. 183, 446 A.2d 716 (1982), the Borough argues that the County has a constitutional right to expand the nonconforming use of the present jail. According to the Borough, the County has no standing to bring this action, because the Ordinance has *159“no adverse impact upon the County’s ability to use its property as it proposes.” We disagree. The County’s right to expand its nonconforming use is not without limitation. Jenkintown, quoting Mattero v. Township of Upper Chichester Zoning Hearing Board, 38 Pa.Commonwealth Ct. 322, 325, 395 A.2d 584, 586 (1978), “recognized that the right to expand a nonconforming use ‘is subject to applicable zoning building regulations and the interest of the public health, safety and welfare[]’_” Jenkintown, 67 Pa.Commonwealth Ct. at 188, 446 A.2d at 719. The County seeks to build a new jail either on the site of the present jail or on the site of the present jail increased by the acquisition of three adjoining residential properties. Assuming arguendo that the Ordinance does not exclude the use of land for a jail, we conclude that the County is adversely affected by provisions of the Ordinance regulating, inter alia, setbacks, building heights, and off-street parking. The County has standing to challenge the validity of the Ordinance.4
The Borough’s third issue concerns whether the Ordinance excludes the use of land for a jail. “Our scope of review, where, as here, the Court of Common Pleas took no additional evidence, is limited to determining whether the Board committed an error of law or an abuse of discretion.” Collins v. Upper Salford Township Board Supervisors, 162 Pa.Commonwealth Ct. 403, 405 n. 1, 639 A.2d 861, 862 n. 1 (1994).
A zoning ordinance is presumptively constitutional; a challenger of a zoning ordinance bears a heavy burden to prove otherwise. However, the challenger can rebut this presumption by demonstrating that the ordinance completely excludes a legitimate use. Once a challenge establishes that a legitimate use is excluded, the burden shifts to the municipality to show that the exclusion is substantially related to the promotion of public health, safety and welfare.
Id. at 407-08, 639 A.2d at 864 (citations omitted). We agree with Common Pleas that the Board erred when it determined that the Ordinance is not de jure exclusionary with regard to the use of land for a jail. The first paragraph of Part 2 of the Ordinance provides as follows:
The uses permitted in each district are listed below. Uses in each category shall be according to the definitions contained in Part 6 of this Chapter, or if not defined, according to the common meaning of the term. Uses not specifically fisted or defined as included in these categories shall not be permitted.
The specified uses do not include use for a jail or prison. The Board determined that jails are permitted because a jail is a government office, which use is permitted in a C-3 Commercial Professional District. However, as Common Pleas correctly analyzed, Section 601 of the Ordinance provides that the principal use is “the primary use or purpose of which a building, structure, and/or land or major portion thereof, is designed, arranged or intended, or for which it may be occupied or maintained_” We agree with Common Pleas that the principal use of a jail and of a government office are different. As the Honorable John Q. Stranahan of the Court of Common Pleas of Beaver County opined,
[t]he ‘primary use or purpose’ of a jail is to house and confine prisoners. While the intended use of the building may require some administrative offices, clearly the primary intended use of the structure is not, in fact, for office space. What it is and what it proposes to be is a jail simply defined as ‘a building designated by law, or regularly used for the confinement of persons held in lawful custody.’ Black’s Law Dictionary 834 (6th ed. 1990).
Once it is determined that a zoning ordinance excludes a legitimate use, the burden shifts to the municipality to establish that the exclusion is designed to protect the public health and welfare. Our review of the record convinces us that the Borough failed to meet its burden.
The Borough’s fourth issue concerns whether Common Pleas abused its discretion by permitting the County to build its *160new jail according to either of the proposed plans. Pursuant to Casey v. Zoning Hearing Board of Warwick Township, 459 Pa. 219, 328 A.2d 464 (1974), a ruling that a zoning ordinance totally excludes a legitimate use is not to be enforced prospectively but must apply to the party who successfully litigated that ordinance’s invalidity. As the Pennsylvania Supreme Court stated in H.R. Miller Company v. Board of Supervisors, 529 Pa. 478, 605 A.2d 321 (1992), “[w]here the cause of an ordinance’s invalidity is a de jure exclusion of a legitimate use, as in Casey, ... the sole remedy is to allow the use somewhere in the municipality, and equity dictates that this opportunity fall to the successful litigant/landowner.” Id. at 485, 605 A.2d at 324-25. When there is a de jure exclusion, “[t]he sole remedy is to allow the use somewhere, and under Casey and Section 1006-A(c) of the Municipalities Planning Code ..., the successful litigant must receive that benefit in the form of at least partial approval of the proposal.” Id. at 486 n. 5, 605 A.2d at 325 n. 5.
In [Appeal of Shore, 524 Pa. 436, 573 A.2d 1011 (1990) ], the [Pennsylvania Supreme] Court interpreted Section 1006-A of the Pennsylvania Municipalities Planning Code ..., 53 P.S. § 11006-A, as providing the courts of common pleas with broad discretion to approve a proposed use_ Following Shore, we hold that the trial court is best situated to determine the extent to which [the] proposal ought to be approved.
Collins, 162 Pa.Commonwealth Ct. at 409-10, 639 A.2d at 864-65. Common Pleas, upon review of the record, concluded that neither of the plans for the new County jail would injure the public health, safety, welfare, or morals and that each was reasonable. We see no abuse of discretion on the part of Common Pleas and will not disturb its conclusions on appeal.
The Borough’s fifth issue concerns whether the County’s application for variances was properly denied. Having determined that the Ordinance de jure excludes the use of land for a jail, we will not address this issue because it is moot.
Accordingly, the May 19, 1994 order of the Court of Common Pleas of Beaver County is affirmed.
ORDER
AND NOW, this 10th day of March, 1995, the order of the Court of Common Pleas of Beaver County in the above-captioned matter is affirmed.
After argument, NEWMAN, J. did not participate in the decision in this case.
. This case was reassigned to President Judge Colins on February 6, 1995.
. This Court held, in a related case, that the County is subject to the Ordinance, because The County Code, Act of August 9, 1955, P.L. 323, as amended, 16 P.S. §§ 101-2901, does not preempt local zoning ordinances. Borough of Beaver v. County of Beaver, 157 Pa.Commonwealth Ct. 185, 629 A.2d 240 (1993), petition for allowance of appeal denied,-Pa.-, -A.2d-(filed November 9, 1993).
.Act of July 31, 1968, P.L. 805, as reenacted and amended by the Act of December 21, 1988, P.L. 1329. Section 910.2 was added by the Act of December 21, 1988.
. The County argues that the Borough has waived this issue because the issue was not raised in the Borough's brief to Common Pleas. The record before this Court does not contain the brief filed with Common Pleas; therefore, we cannot address whether the issue was waived.