GROTON, Conn. — States with large military bases are filling what is traditionally the federal government’s role by picking up the tab for construction and repairs, saying they can’t afford not to.

The number of states willing to spend taxpayer money to fix infrastructure in military facilities, and the scale of the projects, has increased steadily in the past five years. State officials argue the Pentagon keeps asking for base closings and they want to protect their bases and the revenue they bring in.

Essentially, states are treating bases like large corporations they want to keep within their borders, and at least one high-ranking Navy official says it’s a good idea. Connecticut has been a leader, setting aside $40 million to improve aging infrastructure at the naval submarine base there, much like it’s spending hundreds of millions of dollars to keep companies in Connecticut and create jobs.

“We are changing the ways we think about military bases,” said Bob Ross, executive director of Connecticut’s Office of Military Affairs. “These are big commercial enterprises. They are publicly financed, but there is so much commercial activity that goes on at these bases, you have to look at them the same way you look at a corporation.”

Of the nearly two dozen states where the military has a major presence, slightly more than half have spent state money to fix infrastructure on military installations, the Association of Defense Communities has found. Most of the spending occurred after 2009, when the Defense Department’s budget for military construction began shrinking, said Tim Ford, the association’s chief executive officer.

Last year, Massachusetts authorized spending $177 million on its six bases. Cities are contributing, too: Huntsville, Alabama, paid to build houses on an Army post for high-ranking generals.

Most bases are a community’s largest employer, and in many cases are the largest employer in a state, Ford said. They infuse capital into an area through salaries, expenditures and contracts, creating a vibrant economy and tax base and helping other business thrive, he added.

“So now you have this proliferation of other states looking to see how they can provide dollars for their installations,” Ford said. “It has started to raise the question of, how far do you go? Where’s the point by which you have to draw a line, where this is a federal action, this is our federal government, our military, and how much should states really invest?”

States are throwing their money away because these projects won’t be enough to change minds in a future round of base closings, said Jerry Hendrix, of the Center for a New American Security, a Washington think tank on national security and defense policies.

“States should spend money investing in the local community, in health and public safety, and what money they don’t need should return to their people in the form of lower taxes,” said Hendrix, a retired Navy captain and director of the center’s Defense Strategies and Assessments Program.

There also isn’t the political will to close bases now, Hendrix said, so states are spending money to “compete in a competition that hasn’t been declared.”

Dennis McGinn, assistant secretary of the Navy for installations, said he would encourage states to invest in bases to jumpstart projects. Limited military construction funds are being prioritized, he added.

“It is a great win-win partnership. There’s benefit to the state and the local communities. There’s benefit, certainly, to the United States Navy and the Marine Corps where states are doing that,” McGinn said in an interview in Groton last week.